File tree 1 file changed +5
-8
lines changed
compiler/src/dotty/tools/dotc/typer 1 file changed +5
-8
lines changed Original file line number Diff line number Diff line change @@ -409,17 +409,14 @@ object Inferencing {
409
409
Stats .record(" maximizeType" )
410
410
val vs = variances(tp)
411
411
val patternBindings = new mutable.ListBuffer [(Symbol , TypeParamRef )]
412
- val gadtVariances = ctx.gadt.symbols.map(sym => variances( ctx.gadt.bounds(sym ).nn) )
412
+ val gadtBounds = ctx.gadt.symbols.map(ctx.gadt.bounds(_ ).nn)
413
413
vs foreachBinding { (tvar, v) =>
414
414
if ! tvar.isInstantiated then
415
415
// if the tvar is covariant/contravariant (v == 1/-1, respectively) in the input type tp
416
- // then it is safe to instantiate if it has the same variance within the GADT bounds.
417
- // Eg neg/i14983 the C in Node[+C] differs in variance to the GADT bound X >: List[C] so maximising to Node[Any] is unsound
418
- // Eg pos/precise-pattern-type the T in Tree[-T] is in no GADT bound so can maximise to Tree[Type]
419
- val safeToInstantiate = v != 0 && gadtVariances.forall { vmap =>
420
- val v2 = vmap(tvar)
421
- v2 == null || v2 == v
422
- }
416
+ // then it is safe to instantiate if it doesn't occur in any of the GADT bounds.
417
+ // Eg neg/i14983 the C in Node[+C] occurs in GADT bound X >: List[C] so maximising to Node[Any] is unsound
418
+ // Eg pos/precise-pattern-type the T in Tree[-T] doesn't occur in any GADT bound so can maximise to Tree[Type]
419
+ val safeToInstantiate = v != 0 && gadtBounds.forall(! tvar.occursIn(_))
423
420
if safeToInstantiate then tvar.instantiate(fromBelow = v == - 1 )
424
421
else {
425
422
val bounds = TypeComparer .fullBounds(tvar.origin)
You can’t perform that action at this time.
0 commit comments