我似乎找到了处理奇怪错误消息的方法。我正在存储密码,并且有一条评论说

/** A password hash is stored as `"algorithm$iterations$salt$hash"`
 *  with the number of iterations optional for some algorithms

当我尝试为我的项目创建一个分发jar时,收到以下警告:
Variable iterations undefined in comment for...

我将警告跟踪到特征package scala.tools.nsc.ast.DocComments,在那里发现可以在ScalaDoc中放置某种变量。不幸的是,谷歌搜索“Scaladoc中的变量”或“ScalaDoc美元符号”不会返回任何有用的信息。

有谁知道我使用的功能不正确以及如何添加美元符号
在ScalaDoc评论中没有得到警告?

最佳答案

我以“$$”开头,作为猜测。然后,我将尝试使用反斜杠将其转义,这就是答案。

标准lib充满了这些宏。 (例如,在immutable.MapLike中,

 *  @define Coll immutable.Map

用法$Coll,适用于继承的文档。)

您会认为StringInterpolator将显示如何包括一美元。
 [scaladoc] /localhome/jenkins/a/workspace/pr-checkin-per-commit/src/library/scala/StringContext.scala:17: warning: Variable name undefined in comment for class StringContext in class StringContext
 [scaladoc]  *   println(s"Hello, $name")  // Hello, James
 [scaladoc]                        ^
 [scaladoc] /localhome/jenkins/a/workspace/pr-checkin-per-commit/src/library/scala/StringContext.scala:23: warning: Variable name undefined in comment for class StringContext in class StringContext
 [scaladoc]  *   s"Hello, $name"
 [scaladoc]                ^
 [scaladoc] /localhome/jenkins/a/workspace/pr-checkin-per-commit/src/library/scala/StringContext.scala:41: warning: Variable a undefined in comment for class StringContext in class StringContext
 [scaladoc]  *    val x: JSONObject = json"{ a: $a }"
 [scaladoc]                                      ^

那是从sample sanity build for pull requests

所有这些错误均来自类doc,而不是成员doc,因此,这可能只是一个提示。也许到那时候它才停止提示。

该工具在其输出中发出了很棒的引物,但没有涉及到您的问题:
 [scaladoc] Quick crash course on using Scaladoc links
 [scaladoc] ==========================================
 [scaladoc] Disambiguating terms and types: Prefix terms with '$' and types with '!' in case both names are in use:
 [scaladoc]  - [[scala.collection.immutable.List!.apply class List's apply method]] and
 [scaladoc]  - [[scala.collection.immutable.List$.apply object List's apply method]]
 [scaladoc] Disambiguating overloaded members: If a term is overloaded, you can indicate the first part of its signature followed by *:
 [scaladoc]  - [[[scala.collection.immutable.List$.fill[A](Int)(⇒A):List[A]* Fill with a single parameter]]]
 [scaladoc]  - [[[scala.collection.immutable.List$.fill[A](Int,Int)(⇒A):List[List[A]]* Fill with a two parameters]]]
 [scaladoc] Notes:
 [scaladoc]  - you can use any number of matching square brackets to avoid interference with the signature
 [scaladoc]  - you can use \\. to escape dots in prefixes (don't forget to use * at the end to match the signature!)
 [scaladoc]  - you can use \\# to escape hashes, otherwise they will be considered as delimiters, like dots.

更新1:猜猜是什么,这种猜想似乎行得通。它不再在此输出中提示$ROOT:
docs.partest:
 [scaladoc] Documenting 33 source files to /home/apm/projects/snytt/build/scaladoc/partest
 [scaladoc] model contains 110 documentable templates
 [scaladoc] /home/apm/projects/snytt/src/partest/scala/tools/partest/BytecodeTest.scala:14: warning: Variable TESTDIR undefined in comment for class BytecodeTest in class BytecodeTest
 [scaladoc]  * 1. Create subdirectory in test/files/jvm for your test. Let's name it $TESTDIR.
 [scaladoc]                                                                           ^
 [scaladoc] /home/apm/projects/snytt/src/partest/scala/tools/partest/BytecodeTest.scala:15: warning: Variable TESTDIR undefined in comment for class BytecodeTest in class BytecodeTest
 [scaladoc]  * 2. Create $TESTDIR/BytecodeSrc_1.scala that contains Scala source file that you
 [scaladoc]               ^
 [scaladoc] /home/apm/projects/snytt/src/partest/scala/tools/partest/BytecodeTest.scala:18: warning: Variable TESTDIR undefined in comment for class BytecodeTest in class BytecodeTest
 [scaladoc]  * 3. Create $TESTDIR/Test.scala:
 [scaladoc]               ^
 [scaladoc] Document succeeded with 3 warnings; see the documenter output for details.
 [scaladoc] three warnings found
[stopwatch] [docs.partest.timer: 19.486 sec]

现在,我将去$TESTDIR

哇,这真的很授权。谢谢你的问题!

首先让我检查一下scaladoc是否在其html输出中实际包含$ROOT单词。

更新2:你知道吗?只是没关系。结果就是,哈:
 A string that looks like a file path is normalized by replacing the leading segments (the root) with "$$ROOT"

更新3:实际上,\$反斜杠转义工作正常。实际的屏幕实时输出:
with "$ROOT"

关于scala - 是什么导致此Scala错误消息?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18178801/

10-12 19:49