File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
compiler/src/dotty/tools/dotc/core Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -158,6 +158,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
158
158
private inline def inFrozenGadt [T ](inline op : T ): T =
159
159
inFrozenGadtIf(true )(op)
160
160
161
+ /** A flag to prevent recursive joins when comparing AndTypes on the left */
162
+ private var joined = false
163
+
161
164
private inline def inFrozenGadtIf [T ](cond : Boolean )(inline op : T ): T = {
162
165
val savedFrozenGadt = frozenGadt
163
166
frozenGadt ||= cond
@@ -477,11 +480,20 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
477
480
widenOK
478
481
|| joinOK
479
482
|| (tp1.isSoft || constrainRHSVars(tp2)) && recur(tp11, tp2) && recur(tp12, tp2)
480
- || containsAnd(tp1) && inFrozenGadt(recur(tp1.join, tp2))
483
+ || containsAnd(tp1)
484
+ && ! joined
485
+ && {
486
+ joined = true
487
+ try inFrozenGadt(recur(tp1.join, tp2))
488
+ finally joined = false
489
+ }
481
490
// An & on the left side loses information. We compensate by also trying the join.
482
491
// This is less ad-hoc than it looks since we produce joins in type inference,
483
492
// and then need to check that they are indeed supertypes of the original types
484
493
// under -Ycheck. Test case is i7965.scala.
494
+ // On the other hand, we could get a combinatorial explosion by applying such joins
495
+ // recursively, so we do it only once. See i14870.scala as a test case, which would
496
+ // loop for a very long time without the recursion brake.
485
497
486
498
case tp1 : MatchType =>
487
499
val reduced = tp1.reduced
Original file line number Diff line number Diff line change
1
+ abstract class Quantity [A <: Quantity [A ]]
2
+ class Energy extends Quantity [Energy ]
3
+ class Time extends Quantity [Time ]
4
+ class Dimensionless extends Quantity [Dimensionless ]
5
+
6
+ class Price [Q <: Quantity [Q ] & (Energy | Time | Dimensionless )]
You can’t perform that action at this time.
0 commit comments