Open
Description
Using Symbol.docstring from tests to inspect types defined in main always returns None
.
Compiler version
3.3.3
3.4.1
Minimized code
https://github.com/OndrejSpanel/Scala3-DocStringInTest
main:
import scala.quoted.*
object Doc {
inline def of[A]: Option[String] = ${ ofImpl[A] }
def ofImpl[A: Type](using Quotes): Expr[Option[String]] = {
import quotes.reflect.*
val symbol = TypeRepr.of[A].typeSymbol
Expr(symbol.docstring)
}
}
/**
* my doc string for Main
*
* @param tracks track listing
* */
class Main(tracks: String)
object Main {
def main(args: Array[String]): Unit = {
val docString = Doc.of[Main]
println(docString)
}
}
test:
/**
* Doc of Test
* */
class Test
object Test {
def main(args: Array[String]): Unit = {
val docString = Doc.of[Main]
println(docString)
val docStringTest = Doc.of[Test]
println(docStringTest)
if (docString.isEmpty || docStringTest.isEmpty) System.exit(1)
}
}
Use Test/run
to run the code.
Output
None
Some(/**
* Doc of Test
* */)
Note: while test can access values of docstring
defined in test. it cannot access any docstring
defined in main, it always gets None
.
Expectation
The docstring
values of symbols defined in the main should be available from tests.