Skip to content

Improve unused check of macro expansion #11080

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

Open
wants to merge 1 commit into
base: 2.13.x
Choose a base branch
from

Conversation

som-snytt
Copy link
Contributor

Fixes scala/bug#10313

-Vmacro shows the shapeless Record expanding the reference to the type alias X and then eliminating it, but this commit just improves handling of types in the macro expandee. Some code is refactored out in the main traverser and reused in the refCollector (that seeks to collect references but not new definitions from a macro expansion).

Debug output for the example, showing X reached from Y:

AnyRef{type T = shapeless.labelled.FieldType[Symbol @@ String("b"),ex.Foo.X] :: shapeless.HNil} referenced from type Y
shapeless.labelled.FieldType[Symbol @@ String("b"),ex.Foo.X] :: shapeless.HNil referenced from type Y
shapeless.labelled.FieldType[Symbol @@ String("b"),ex.Foo.X] referenced from type Y
Symbol @@ String("b") referenced from type Y
alias ex.Foo.X referenced from type Y

(Still needs a standalone test.)

@scala-jenkins scala-jenkins added this to the 2.13.17 milestone Jun 21, 2025
@som-snytt som-snytt force-pushed the issue/10313-macro-usages branch from d81cd10 to a146146 Compare June 21, 2025 23:55
@som-snytt
Copy link
Contributor Author

Reminder: the macro expansion attachment is on each of the expandee - expansion pair. (It is not an "original" link that can be followed for "chained" expansions.) The expandee gets "regular" traversal (super.traverse), the expansion gets refcollector; other trees also get regular super.traverse.

@som-snytt som-snytt force-pushed the issue/10313-macro-usages branch from a146146 to b70db71 Compare June 22, 2025 00:04
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.

-Xlint:unused false positive with type alias
2 participants