-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 #21402: Always allow type member extraction for stable scrutinees in match types. #21700
Conversation
/* If it is a skolem type, we cannot have class selections nor | ||
* abstract type selections. If it is an alias, we try to remove | ||
* any reference to the skolem from the right-hand-side. If that | ||
* succeeds, we take the result, otherwise we fail as not-specific. | ||
*/ | ||
def adaptToTriggerNotSpecific(info: Type): Type = info match |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the doc comment refers to the code below starting with denot.info match
, not to the behavior of the def itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's about the whole body of the case SkolemType
. I added a blank line, which hopefully makes it not misleading anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, usually we write those comments with //
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought /*
was just the multi-line version of //
, whereas /**
is the doc-of-the-def
thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah using /*
is fine, just uncommon in this codebase I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always doc'd local defs with /*
seeing as the docs don't appear anywhere in the scaladocs anyways, to not be misleading as to that. It's funny how that thought process leads to unintended confusion in this case 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to add a minimal testcase to illustrate the feature.
…inees in match types. Previously, through the various code paths, we basically allowed type member extraction for stable scrutinees if the type member was an alias or a class member. In the alias case, we took the alias, whereas in the class case, we recreated a selection on the stable scrutinee. We did not allow that on abstract type members. We now uniformly do it for all kinds of type members. If the scrutinee is a (non-skolem) stable type, we do not even look at the info of the type member. We directly create a selection to it, which corresponds to what we did before for class members. We only try to dealias type members if the scrutinee type is not a stable type.
|
||
def adaptToTriggerNotSpecific(info: Type): Type = info match | ||
case info: TypeBounds => info | ||
case _ => RealTypeBounds(info, info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks similar to Type#bounds. That might or might not be appropriate here, but wanted to bring it to your attention.
I'm surprised that the spec language in https://docs.scala-lang.org/sips/match-types-spec.html isn't part of the spec in this repo. |
I did not have time to integrate it yet. :( |
Previously, through the various code paths, we basically allowed type member extraction for stable scrutinees if the type member was an alias or a class member. In the alias case, we took the alias, whereas in the class case, we recreated a selection on the stable scrutinee. We did not allow that on abstract type members.
We now uniformly do it for all kinds of type members. If the scrutinee is a (non-skolem) stable type, we do not even look at the info of the type member. We directly create a selection to it, which corresponds to what we did before for class members.
We only try to dealias type members if the scrutinee type is not a stable type.
Note that this goes against the current spec and should in theory require (yet another) SIP amendment. The core meeting decided a few ago to go for it anyway and "ask for forgiveness" later so that we can have it in 3.6.0 🤷♂️.