Skip to content

Commit 3ef00b9

Browse files
committed
Fix collection of bound type variables in UnApply patterns
1 parent a582243 commit 3ef00b9

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,16 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
720720
foldOver(syms1, t)
721721
}
722722
}
723-
val boundVars = getBoundVars(Nil, tpt)
723+
var boundVars = getBoundVars(Nil, tpt)
724+
// UnApply nodes with pattern bound variables translate to something like this
725+
// UnApply[t @ t](pats)(implicits): T[t]
726+
// Need to traverse any binds in type arguments of the UnAppyl to get the set of
727+
// all instantiable type variables. Test case is pos/inline-caseclass.scala.
728+
pat1 match {
729+
case UnApply(TypeApply(_, tpts), _, _) =>
730+
for (tpt <- tpts) boundVars = getBoundVars(boundVars, tpt)
731+
case _ =>
732+
}
724733
for (bv <- boundVars) ctx.gadt.setBounds(bv, bv.info.bounds)
725734
scrut <:< tpt.tpe && {
726735
for (bv <- boundVars) {

tests/pos/inline-caseclass.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
trait Nat
2+
case object Z extends Nat
3+
case class S[N <: Nat](n: N) extends Nat
4+
5+
object Test {
6+
type Z = Z.type
7+
8+
inline def add(x: Nat, y: Int) <: Int = inline x match {
9+
case Z => y
10+
case S(x1) => add(x1, y) + 1
11+
}
12+
13+
val x = S(S(Z))
14+
val a: 2 = add(Z, 2)
15+
inline val y = add(x, 2)
16+
val z: 4 = y
17+
18+
}
19+

0 commit comments

Comments
 (0)