Skip to content

Commit 1636a25

Browse files
authored
Merge pull request #5914 from dotty-staging/missing-frozen-constraint-case
Attempt to fix a potentially missing case in TypeComparer
2 parents 32cbb44 + f6d037a commit 1636a25

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,11 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
482482
// widening in `fourthTry` before adding to the constraint.
483483
if (frozenConstraint) recur(tp1, bounds(tp2).lo)
484484
else isSubTypeWhenFrozen(tp1, tp2)
485-
alwaysTrue || {
485+
alwaysTrue ||
486+
frozenConstraint && (tp1 match {
487+
case tp1: TypeParamRef => constraint.isLess(tp1, tp2)
488+
case _ => false
489+
}) || {
486490
if (canConstrain(tp2) && !approx.low)
487491
addConstraint(tp2, tp1.widenExpr, fromBelow = true)
488492
else fourthTry
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dotty.tools.dotc.typer
2+
3+
import dotty.tools.DottyTest
4+
import dotty.tools.dotc.core.Contexts.Context
5+
import dotty.tools.dotc.core.Types.TypeBounds
6+
import dotty.tools.dotc.typer.ProtoTypes.newTypeVar
7+
import org.junit.Test
8+
9+
class SubtypingInvariantTests extends DottyTest {
10+
11+
@Test
12+
def typeVarInvariant(): Unit = {
13+
checkCompile("frontend", "class A") { (_, ctx0) =>
14+
implicit val ctx: Context = ctx0
15+
val a = newTypeVar(TypeBounds.empty)
16+
val b = newTypeVar(TypeBounds.empty)
17+
assert(a <:< b)
18+
assert(a frozen_<:< b)
19+
}
20+
}
21+
22+
}

0 commit comments

Comments
 (0)