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

Set Span for top level annotations generated in PostTyper #16378

Merged
merged 2 commits into from
Dec 22, 2022

Conversation

jchyb
Copy link
Contributor

@jchyb jchyb commented Nov 18, 2022

This should help avoid macros throwing assertion errors in the case of annotations not having assigned Spans/positions. Since the annotation is generated and does not have a position corresponding to the source file, it inherits Span from the tree to which it is assigned.

Fixes #16318

@jchyb jchyb marked this pull request as ready for review November 21, 2022 13:01
@nicolasstucki nicolasstucki assigned jchyb and unassigned nicolasstucki Nov 21, 2022
@Kordyjan Kordyjan modified the milestones: Future versions, 3.3.0-RC1 Dec 12, 2022
This should help avoid macros throwing assertion errors in the case of
annotations not having assigned Spans/positions. Since the annotation is
generated and does not have a position corresponding to the source file,
it inherits Span from the tree to which it is assigned.
@jchyb jchyb force-pushed the fix-16318 branch 4 times, most recently from cc74d95 to db5b398 Compare December 21, 2022 13:34
@jchyb jchyb assigned nicolasstucki and unassigned jchyb Dec 21, 2022
@jchyb
Copy link
Contributor Author

jchyb commented Dec 21, 2022

Hi @nicolasstucki apologies for being so late with this. I was not entirely sure on what you meant in the above comment, so in the end I decided to add two commits. The first one fixes the issue by adding spans to all generated annotations in PostTyper, like before. This alone fixes the #16318, and adds annotations to two additional places where the issue has a chance to reappear (so this includes every annotation generated in PostTyper).

In the second commit, I make sure to add the span to every generated annotation in the compiler. For that I adjusted Annotation.apply methods to always require a span argument. This was obviously helpful for me, as it allowed me to easily locate span-less Annotations, and hopefully will be for others later, even if it is not futureproof (one can still pass a NoSpan, if necessary, in general it’s meant to be more of a remainder).

However, if the contents of the second commit end up being unnecessary, I can easily remove it from the PR and we can proceed with just the first commit.

Copy link
Contributor

@nicolasstucki nicolasstucki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

compiler/src/dotty/tools/dotc/ast/Desugar.scala Outdated Show resolved Hide resolved
@nicolasstucki
Copy link
Contributor

However, if the contents of the second commit end up being unnecessary, I can easily remove it from the PR and we can proceed with just the first commit.

The contents of the second commit are necessary. That is what I felt was missing before.

Achieved by removing the apply methods without a span argument,
which would generate Annotation trees with empty spans. One can still
put NoSpan as the span argument, so this will not make much of a
difference, but will hopefully provide an additional incentive to always
add one.
@jchyb
Copy link
Contributor Author

jchyb commented Dec 21, 2022

Thank you for the review! I also just realized I @ the wrong person in my comment above before, for which I apologize, should be edited correctly now

@nicolasstucki nicolasstucki merged commit 8ee91a4 into scala:main Dec 22, 2022
@Kordyjan Kordyjan modified the milestones: 3.3.0-RC1, 3.3.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Position not set error for SourceFile annotation, when accessed from a transparent macro
3 participants