Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbol.docString not available in tests #20106

Open
OndrejSpanel opened this issue Apr 5, 2024 · 5 comments
Open

Symbol.docString not available in tests #20106

OndrejSpanel opened this issue Apr 5, 2024 · 5 comments
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:bug

Comments

@OndrejSpanel
Copy link
Member

OndrejSpanel commented Apr 5, 2024

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

Workflow 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.

@OndrejSpanel OndrejSpanel added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 5, 2024
@nicolasstucki
Copy link
Contributor

What is the definition of Main?

@nicolasstucki nicolasstucki added area:metaprogramming:reflection Issues related to the quotes reflection API and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 5, 2024
@OndrejSpanel
Copy link
Member Author

Added. Getting docstring of Main works fine from main sources, not from test.

Complete project is linked in the issue, as well as the workflow output demonstrating the failure.

@nicolasstucki
Copy link
Contributor

It seems that we are not loading the docstrings from TASTy. This can be enabled with -Yread-docs, but users should not use that. The ContextDocstrings should be able to load documentation on demand.

@OndrejSpanel
Copy link
Member Author

Glad to hear you are making progress on this.

What is the difference between loading main and test docstrings from test? Because main from main works, as well as test from test. Are they read from other place than TASTy in such case?

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 10, 2024
Now we are always able to load docstings from TASTy, even if `-Yread-docs` is not set.
The `-Yread-docs` flag loads the doc strings eagerly, as it did before.

Fixes scala#20106
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 10, 2024
Now we are always able to load docstings from TASTy, even if `-Yread-docs` is not set.
The `-Yread-docs` flag loads the doc strings eagerly, as it did before.

Fixes scala#20106
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 10, 2024
Now we are always able to load docstings from TASTy, even if `-Yread-docs` is not set.
The `-Yread-docs` flag loads the doc strings eagerly, as it did before.

Fixes scala#20106
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 10, 2024
Now we are always able to load docstings from TASTy, even if `-Yread-docs` is not set.
The `-Yread-docs` flag loads the doc strings eagerly, as it did before.

Fixes scala#20106
@nicolasstucki
Copy link
Contributor

What is the difference between loading main and test docstrings from test? Because main from main works, as well as test from test. Are they read from other place than TASTy in such case?

In that case, they come directly from the parsed source file. You may also be missing the documentation if there is an incremental compilation and part of the files are related from TASTy from the previous compilation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants