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

Fix unreachable warning in deeply nested sealed hierarchy #18706

Merged
merged 4 commits into from
Oct 20, 2023

Conversation

dwijnand
Copy link
Member

No description provided.

@dwijnand dwijnand linked an issue Oct 17, 2023 that may be closed by this pull request
Without applying we were constructing the type Jacket#Body, instead of
Jacket[?]#Body, which lead down to an incorrect isSubSpace calculation
and thus an unreachable warning.
@dwijnand dwijnand force-pushed the nested-nested-nested-in-generic-parent branch from 7ccba02 to 9460b7d Compare October 17, 2023 10:35
@dwijnand dwijnand marked this pull request as ready for review October 18, 2023 13:38
@dwijnand dwijnand assigned liufengyun and unassigned dwijnand Oct 18, 2023
@@ -883,7 +883,7 @@ object TypeOps:
else if symbol.is(Module) then
TermRef(this(tref.prefix), symbol.sourceModule)
else if (prefixTVar != null)
this(tref)
this(tref.applyIfParameterized(tref.typeParams.map(_ => WildcardType)))
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not clear why this is correct.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to detail it in the commit message (9460b7d) - given something like:

class Jacket[T]:
  sealed trait BodyType

As we map over the type Jacket.this.BodyType we don't want to take the raw type Jacket, stripped from its ThisType wrapper, and have it be the prefix of BodyType, because we would then get Jacket#BodyType which is ill-formed. Instead we mean to refer to any the BodyType nested class of any Jacket: Jacket[?]#BodyType.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation. I now see the type will be upper bound for prefixTVar, so it's harmless.

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -883,7 +883,7 @@ object TypeOps:
else if symbol.is(Module) then
TermRef(this(tref.prefix), symbol.sourceModule)
else if (prefixTVar != null)
this(tref)
this(tref.applyIfParameterized(tref.typeParams.map(_ => WildcardType)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation. I now see the type will be upper bound for prefixTVar, so it's harmless.

@dwijnand dwijnand merged commit 5b416fa into scala:main Oct 20, 2023
18 checks passed
@dwijnand dwijnand deleted the nested-nested-nested-in-generic-parent branch October 20, 2023 07:22
@Kordyjan Kordyjan added this to the 3.4.0 milestone Dec 20, 2023
WojciechMazur added a commit that referenced this pull request Jun 22, 2024
…to LTS (#20727)

Backports #18706 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
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.

False unreachable warning when matching alternative projection types
3 participants