Skip to content

Fix #12408: Parameterized classes should be applied for prefix inference #12424

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

Merged
merged 1 commit into from
May 12, 2021

Conversation

liufengyun
Copy link
Contributor

Fix #12408: Parameterized classes should be applied for prefix inference

@liufengyun liufengyun requested a review from dwijnand May 12, 2021 07:08
@dwijnand
Copy link
Member

There already was a recursive this(tref) call, so why weren't parameterized classes inferring their prefix already?

@liufengyun
Copy link
Contributor Author

There already was a recursive this(tref) call, so why weren't parameterized classes inferring their prefix already?

The recursive this(tref) will substitute prefix with type variables, the actual inference happens later. The issue here is that before this change, the bound of the type variable has the wrong kind -- thus the subtyping A' <: P is false. This disqualifies A/B/C as valid children of P. Consequently, P decomposes to empty thus the warning about null.

Copy link
Member

@dwijnand dwijnand left a comment

Choose a reason for hiding this comment

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

I feel less sure about wiping out the bounds: if X were class X[T <: Foo] then when X.this.A is replaced with Y.A then I take it Y <: X[?] but I feel it should be Y <: X[? <: Foo]...

But nothing seems to be broken in CI validation.

@liufengyun
Copy link
Contributor Author

I feel less sure about wiping out the bounds: if X were class X[T <: Foo] then when X.this.A is replaced with Y.A then I take it Y <: X[?] but I feel it should be Y <: X[? <: Foo]...

Good point. Here we assume the user writing reasonable code such that the bounds don't affect the prefix. Otherwise, many things would become subtle (typeclass derivation, match types, etc.). We can revisit the assumption if a valid use case does appear.

@dwijnand
Copy link
Member

We can revisit the assumption if a valid use case does appear.

Sounds good to me.

@dwijnand dwijnand merged commit d7a922a into scala:master May 12, 2021
@dwijnand dwijnand deleted the fix-12408 branch May 12, 2021 14:21
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 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.

Spurious "Only null is matched" warning due to nesting?
3 participants