Fixes #21383 enable Mode.ReadPositions when reading annotation trees#25911
Open
soronpo wants to merge 1 commit intoscala:mainfrom
Open
Fixes #21383 enable Mode.ReadPositions when reading annotation trees#25911soronpo wants to merge 1 commit intoscala:mainfrom
soronpo wants to merge 1 commit intoscala:mainfrom
Conversation
Annotation trees stored in TASTY are read lazily. When a macro inspects a
symbol's annotations via `Symbol.annotations`/`asExprOf` and splices the
annotation tree into its expansion, the spliced tree is later re-typed
by InlineTyper (which extends ReTyper/Typer). During this re-typing the
compiler asserts that every untyped tree has a span
(Typer.assertPositioned).
For incremental compilation the enclosing unpickling does not use
Mode.ReadPositions, so `spanAt` and `sourcePathAt` return NoSpan/"" and
the deserialized annotation tree has NoSpan all the way down. That in
turn makes the re-typing of the macro expansion crash with:
assertion failed: position not set for new <AnnotClass>
of class dotty.tools.dotc.ast.Trees$Select
This happens for any annotation argument whose tree gets embedded into
a macro's output — the original report uses @SqlName on a case class
that is then processed by the `TableInfo` transparent inline from
`magnum`, but the bug is fully general.
Force Mode.ReadPositions (and refresh the source from the pickled
source map) when materializing the lazy annotation tree, mirroring
what is already done for inline method bodies. With the mode enabled
the pickled spans are restored and the re-typer is happy.
Adds a self-contained regression test (`tests/pos-macros/i21383`) and
an sbt incremental-compilation test (`sbt-test/source-dependencies/i21383`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Annotation trees stored in TASTY are read lazily. When a macro inspects a symbol's annotations via
Symbol.annotations/asExprOfand splices the annotation tree into its expansion, the spliced tree is later re-typed by InlineTyper (which extends ReTyper/Typer). During this re-typing the compiler asserts that every untyped tree has a span (Typer.assertPositioned).For incremental compilation the enclosing unpickling does not use Mode.ReadPositions, so
spanAtandsourcePathAtreturn NoSpan/"" and the deserialized annotation tree has NoSpan all the way down. That in turn makes the re-typing of the macro expansion crash with:assertion failed: position not set for new
of class dotty.tools.dotc.ast.Trees$Select
This happens for any annotation argument whose tree gets embedded into a macro's output — the original report uses @SqlName on a case class that is then processed by the
TableInfotransparent inline frommagnum, but the bug is fully general.Force Mode.ReadPositions (and refresh the source from the pickled source map) when materializing the lazy annotation tree, mirroring what is already done for inline method bodies. With the mode enabled the pickled spans are restored and the re-typer is happy.
Adds a self-contained regression test (
tests/pos-macros/i21383) and an sbt incremental-compilation test (sbt-test/source-dependencies/i21383).Fixes #21383
How much have you relied on LLM-based tools in this contribution?
Extensively, but it's a small fix.
How was the solution tested?
New automated tests (including the issue's reproducer, if applicable)