Skip to content

Commit f6d037a

Browse files
committed
Attempt to fix a potentially missing case in TypeComparer
1 parent dec3404 commit f6d037a

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
@@ -451,7 +451,11 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
451451
// widening in `fourthTry` before adding to the constraint.
452452
if (frozenConstraint) isSubType(tp1, bounds(tp2).lo)
453453
else isSubTypeWhenFrozen(tp1, tp2)
454-
alwaysTrue || {
454+
alwaysTrue ||
455+
frozenConstraint && (tp1 match {
456+
case tp1: TypeParamRef => constraint.isLess(tp1, tp2)
457+
case _ => false
458+
}) || {
455459
if (canConstrain(tp2) && !approx.low)
456460
addConstraint(tp2, tp1.widenExpr, fromBelow = true)
457461
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)