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

CheckUnused checks span.exists before testing its parts #22504

Merged
merged 2 commits into from
Feb 24, 2025

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Feb 3, 2025

Must check span.exists before using start or point.

Can use pointDelta safely.

It's not obvious that certain checks for isSynthetic should require exists, since those tests will not pass for unpositioned trees. (todo) (synthetic is orthogonal to existing)

Needs a test for producing unpositioned Ident. (todo) It's not unpositioned but spanless. The underlying bug was fixed in 3.3.5 (a macro produced an inlined annotated type tree with the symptom).

Also restore alias "unsafe-warn-patvars". Fix typo in other description.

Fixes #22499

@som-snytt
Copy link
Contributor Author

The hosted runner: GitHub Actions 13 lost communication with the server. Anything in your workflow that terminates the runner process, starves it for CPU/Memory, or blocks its network access can cause this error.

That's called blaming the victim.

@som-snytt som-snytt force-pushed the issue/22499-check-nospan branch 2 times, most recently from bb86c49 to 27224a4 Compare February 4, 2025 17:44
@som-snytt som-snytt marked this pull request as ready for review February 5, 2025 01:22
@Gedochao Gedochao requested a review from Linyxus February 13, 2025 07:42
Copy link
Contributor

@Linyxus Linyxus left a comment

Choose a reason for hiding this comment

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

The only thing seems to be missing is an accompanying test case. I see that it is left as a todo in the description, what is the status on that? Otherwise LGTM! 👍

@som-snytt
Copy link
Contributor Author

som-snytt commented Feb 14, 2025

The (any: @unchecked).isInstanceOf that is inlined from magnolia results in a tree.tpe with the annotation:

  override def transformTypeTree(tree: TypeTree)(using Context): tree.type =
    tree.tpe match
    case AnnotatedType(_, annot) => transformAllDeep(annot.tree)

The annot.tree has the spanless Ident.

Edit: that's what I did not yet reproduce in a dotty test. I assume (without evidence) that it's a bug to see a spanless tree. I suspected tasty, special handling of isInstanceOf, or tree copying for derived. Or "annotations are special".

By cosmic coincidence, it is the unchecked restored the other day in softwaremill/magnolia@5a030d8.

@som-snytt
Copy link
Contributor Author

som-snytt commented Feb 18, 2025

I confirmed that tgbot-utils compiles (emits warnings without crashing) under 3.6.3 after ingesting magnolia.

@som-snytt
Copy link
Contributor Author

Presumably the symptom requires more than separate compilation, but I haven't looked at what's required in a test rig.

@som-snytt
Copy link
Contributor Author

I will probably give up on constructing a test. I confirmed that 3.3.5 fixes the bug (Ident tree with no span in annotated type).

I submitted a PR to Magnolia, which is used by the failing projects. Magnolia built by 3.3.3 or 3.3.4 results in the spanless tree in derived code after inlining.

For a test, I tried a macro that attempts to reset the tree span to NoSpan, but I couldn't get that to fail.

@som-snytt
Copy link
Contributor Author

Probably not fixed by #20445
but maybe by #19957

@Linyxus
Copy link
Contributor

Linyxus commented Feb 24, 2025

Thanks for investigating! LGTM

@som-snytt som-snytt merged commit 7ad8418 into scala:main Feb 24, 2025
29 checks passed
@som-snytt som-snytt deleted the issue/22499-check-nospan branch February 24, 2025 23:44
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.

Regression in CheckUnused leads to compiler crash
2 participants