Skip to content

Commit 4d44638

Browse files
authored
Freeze constraints in a condition check of maximiseType (#16526)
2 parents bd86363 + b0e4ca0 commit 4d44638

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

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

-4
Original file line numberDiff line numberDiff line change
@@ -881,10 +881,6 @@ object TypeOps:
881881
}
882882

883883
def instantiate(): Type = {
884-
// if there's a change in variance in type parameters (between subtype tp1 and supertype tp2)
885-
// then we don't want to maximise the type variables in the wrong direction.
886-
// For instance 15967, A[-Z] and B[Y] extends A[Y], we don't want to maximise Y to Any
887-
maximizeType(protoTp1.baseType(tp2.classSymbol), NoSpan)
888884
maximizeType(protoTp1, NoSpan)
889885
wildApprox(protoTp1)
890886
}

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ object Inferencing {
417417
if safeToInstantiate then tvar.instantiate(fromBelow = v == -1)
418418
else {
419419
val bounds = TypeComparer.fullBounds(tvar.origin)
420-
if bounds.hi <:< bounds.lo || bounds.hi.classSymbol.is(Final) then
420+
if (bounds.hi frozen_<:< bounds.lo) || bounds.hi.classSymbol.is(Final) then
421421
tvar.instantiate(fromBelow = false)
422422
else {
423423
// We do not add the created symbols to GADT constraint immediately, since they may have inter-dependencies.

tests/pos/i16339.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// scalac: -Werror
2+
sealed trait Get[X, +X2 <: X]
3+
case class Bar[Y, Y2 <: Y](value: Y2) extends Get[Y, Y2]
4+
5+
class Test:
6+
def t1[Z, Z2 <: Z](get: Get[Z, Z2]) = get match
7+
case Bar(_) =>

0 commit comments

Comments
 (0)