Skip to content

Commit 63a467b

Browse files
authored
Merge pull request #11543 from dotty-staging/fix-9759
Add missing substitution for pattern-bound variables
2 parents e1de43d + 8cd5d51 commit 63a467b

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ object Inferencing {
393393
def maximizeType(tp: Type, span: Span, fromScala2x: Boolean)(using Context): List[Symbol] = {
394394
Stats.record("maximizeType")
395395
val vs = variances(tp)
396-
val patternBound = new mutable.ListBuffer[Symbol]
396+
val patternBindings = new mutable.ListBuffer[(Symbol, TypeParamRef)]
397397
vs foreachBinding { (tvar, v) =>
398398
if (v == 1) tvar.instantiate(fromBelow = false)
399399
else if (v == -1) tvar.instantiate(fromBelow = true)
@@ -406,11 +406,17 @@ object Inferencing {
406406
// Instead, we simultaneously add them later on.
407407
val wildCard = newPatternBoundSymbol(UniqueName.fresh(tvar.origin.paramName), bounds, span, addToGadt = false)
408408
tvar.instantiateWith(wildCard.typeRef)
409-
patternBound += wildCard
409+
patternBindings += ((wildCard, tvar.origin))
410410
}
411411
}
412412
}
413-
val res = patternBound.toList
413+
val res = patternBindings.toList.map { (boundSym, _) =>
414+
// substitute bounds of pattern bound variables to deal with possible F-bounds
415+
for (wildCard, param) <- patternBindings do
416+
boundSym.info = boundSym.info.substParam(param, wildCard.typeRef)
417+
boundSym
418+
}
419+
414420
// We add the created symbols to GADT constraint here.
415421
if (res.nonEmpty) ctx.gadt.addToConstraint(res)
416422
res

tests/pos-deep-subtype/i9759.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sealed trait Expr[A <: Expr[A]]
2+
3+
case class Equals[A <: Value[A]](lhs: Expr[A], rhs: Expr[A]) extends Expr[Value.Boolean]
4+
5+
sealed trait Value[A <: Value[A]] extends Expr[A]
6+
object Value {
7+
case class String(value: java.lang.String) extends Value[String]
8+
case class Int(value: Long) extends Value[Int]
9+
case class Boolean(value: java.lang.Boolean) extends Value[Boolean]
10+
}
11+
12+
object Main extends App {
13+
def evaluate[A <: Value[A]](expr: Expr[A]): A = expr match {
14+
case Equals(Value.String(lhs), Value.String(rhs)) => Value.Boolean(lhs == rhs)
15+
}
16+
}

0 commit comments

Comments
 (0)