-
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 match type instantiation when not approximating #17173
Conversation
4b3ddca
to
d28c1df
Compare
When not approximating parameters, keep the constraint entries in a Range, so it can propagate through instantiateParams's ApproximatingTypeMap.
d28c1df
to
4f1431d
Compare
If I understand correctly this will essentially disallow all variable instantiations in the mode
This is more restrictive than #17180, which still allows to instantiate invariant type variables even if |
Yes, indeed - running locally:
|
Actually, as TypeAccumulator is also traversing the type, we do have the variance information to instantiate for invariance. |
@@ -3095,7 +3095,7 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) { | |||
def paramInstances(canApprox: Boolean) = new TypeAccumulator[Array[Type]]: | |||
def apply(insts: Array[Type], t: Type) = t match | |||
case param @ TypeParamRef(b, n) if b eq caseLambda => | |||
def range1(tp: Type) = Range(tp, tp) | |||
def range1(tp: Type) = if variance == 0 then tp else Range(tp, tp) |
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 think that's still not as precise as the original solution. The original solution says:
Don't widen if the compared-to type contains variant named type parameters
Whereas here we implement a global criterion:
Under mode
canWidenAbstract = true
, don't instantiate variant named type parameters.
The original proposal would allow the instantiation of variant type parameters if they appear in a part of the pattern that does not correspond to a widened part of the scrutinee. Note: so far we only looked at widening of the scrutinee type as a whole, but one can easily imagine that only subparts are subject to widenings. We need tests for this! The whole thing is woefully under-tested.
It would be really good to work out the theory here. The fact that this is missing in the match type papers and thesis is a big problem.
4520faa
to
f331bcb
Compare
Looking at #17180 |
When not approximating parameters, keep the constraint entries in a Range, so it can propagate through instantiateParams's ApproximatingTypeMap.