Skip to content

Commit 960858d

Browse files
authored
Rollback constraints if isSameType failed second direction (#20109)
It turns out the following assertion does not hold in the current definition of `isSameType` ```scala 3 val preConstraint = constraint val isSame = isSubType(tp1, tp2) && isSubType(tp2, tp1) isSame.ensuring(_ || constraint == preConstraint) ``` I didn't try to form a minimised snippet where this would cause a problem. But as an example, the code in #19955 (comment) produces invalid constraints which lead to suspicious looking `<notypes>`s in the subtyping trace.
2 parents 85672a0 + 8e119ef commit 960858d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/core/TypeComparer.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
23042304
Stats.record("cache same type")
23052305
sames = new util.EqHashMap()
23062306
val res =
2307-
try isSubType(tp1, tp2) && isSubType(tp2, tp1)
2307+
try rollbackConstraintsUnless(isSubType(tp1, tp2) && isSubType(tp2, tp1))
23082308
finally
23092309
sameLevel -= 1
23102310
sames = savedSames

0 commit comments

Comments
 (0)