diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 5d2367a633b5..de7047b10484 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -451,7 +451,11 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] { // widening in `fourthTry` before adding to the constraint. if (frozenConstraint) isSubType(tp1, bounds(tp2).lo) else isSubTypeWhenFrozen(tp1, tp2) - alwaysTrue || { + alwaysTrue || + frozenConstraint && (tp1 match { + case tp1: TypeParamRef => constraint.isLess(tp1, tp2) + case _ => false + }) || { if (canConstrain(tp2) && !approx.low) addConstraint(tp2, tp1.widenExpr, fromBelow = true) else fourthTry diff --git a/compiler/test/dotty/tools/dotc/typer/SubtypingInvariantTests.scala b/compiler/test/dotty/tools/dotc/typer/SubtypingInvariantTests.scala new file mode 100644 index 000000000000..01fac8870a2a --- /dev/null +++ b/compiler/test/dotty/tools/dotc/typer/SubtypingInvariantTests.scala @@ -0,0 +1,22 @@ +package dotty.tools.dotc.typer + +import dotty.tools.DottyTest +import dotty.tools.dotc.core.Contexts.Context +import dotty.tools.dotc.core.Types.TypeBounds +import dotty.tools.dotc.typer.ProtoTypes.newTypeVar +import org.junit.Test + +class SubtypingInvariantTests extends DottyTest { + + @Test + def typeVarInvariant(): Unit = { + checkCompile("frontend", "class A") { (_, ctx0) => + implicit val ctx: Context = ctx0 + val a = newTypeVar(TypeBounds.empty) + val b = newTypeVar(TypeBounds.empty) + assert(a <:< b) + assert(a frozen_<:< b) + } + } + +}