Skip to content

Commit

Permalink
Rollback constraints if isSameType failed second direction (#20109)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odersky committed Apr 6, 2024
2 parents 85672a0 + 8e119ef commit 960858d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2304,7 +2304,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
Stats.record("cache same type")
sames = new util.EqHashMap()
val res =
try isSubType(tp1, tp2) && isSubType(tp2, tp1)
try rollbackConstraintsUnless(isSubType(tp1, tp2) && isSubType(tp2, tp1))
finally
sameLevel -= 1
sames = savedSames
Expand Down

0 comments on commit 960858d

Please sign in to comment.