File tree 3 files changed +25
-2
lines changed
compiler/src/dotty/tools/dotc/core
3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ trait ConstraintHandling {
57
57
b match {
58
58
case b : AndOrType => occursIn(b.tp1) || occursIn(b.tp2)
59
59
case b : TypeVar => occursIn(b.origin)
60
+ case b : TermRef => occursIn(b.underlying)
60
61
case _ => false
61
62
}
62
63
}
Original file line number Diff line number Diff line change @@ -375,11 +375,22 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
375
375
thirdTryNamed(tp1, tp2)
376
376
case tp2 : PolyParam =>
377
377
def comparePolyParam =
378
- (ctx.mode is Mode .TypevarsMissContext ) ||
379
- isSubTypeWhenFrozen(tp1, bounds(tp2).lo) || {
378
+ (ctx.mode is Mode .TypevarsMissContext ) || {
379
+ val alwaysTrue =
380
+ // The following condition is carefully formulated to catch all cases
381
+ // where the subtype relation is true without needing to add a constraint
382
+ // It's tricky because we might need to either appriximate tp2 by its
383
+ // lower bound or else widen tp1 and check that the result is a subtype of tp2.
384
+ // So if the constraint is not yet frozen, we do the same comparison again
385
+ // with a frozen constraint, which means that we get a chance to do the
386
+ // widening in `fourthTry` before adding to the constraint.
387
+ if (frozenConstraint || alwaysFluid) isSubType(tp1, bounds(tp2).lo)
388
+ else isSubTypeWhenFrozen(tp1, tp2)
389
+ alwaysTrue || {
380
390
if (canConstrain(tp2)) addConstraint(tp2, tp1.widenExpr, fromBelow = true )
381
391
else fourthTry(tp1, tp2)
382
392
}
393
+ }
383
394
comparePolyParam
384
395
case tp2 : RefinedType =>
385
396
def compareRefinedSlow : Boolean = {
Original file line number Diff line number Diff line change
1
+ object Test {
2
+ class CC2 [A , B ](a : A , b : B )
3
+
4
+ type T2 [A , B ] = CC2 [A , B ]
5
+
6
+ class ArrowAssoc [A ](val self : A ) {
7
+ @ inline def f [B ](y : B ): CC2 [A , B ] = new CC2 (self, y)
8
+ }
9
+
10
+ def foo = (new ArrowAssoc (1 )).f(2 )
11
+ }
You can’t perform that action at this time.
0 commit comments