Skip to content

Commit 0298581

Browse files
authored
Fix errors in explicit type annotations in inline match cases (#16257)
Previously, Unapply trees would have type bindings generated inside their body and this was the only case handled in InlineReducer. However, this mainly happened for inferred type parameters, and Unapply with an explicit binding inside a type annotation was not handled, leading to a "cannot reduce match" error. This case is now handled and a related comment was added as well.
2 parents b47aa93 + a31cab3 commit 0298581

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala

+12-3
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,21 @@ class InlineReducer(inliner: Inliner)(using Context):
269269
}
270270
}
271271

272-
// Extractors contain Bind nodes in type parameter lists, the tree looks like this:
272+
// Extractors can contain Bind nodes in type parameter lists,
273+
// for that case tree looks like this:
273274
// UnApply[t @ t](pats)(implicits): T[t]
274275
// Test case is pos/inline-caseclass.scala.
276+
// Alternatively, for explicitly specified type binds in type annotations like in
277+
// case A(B): A[t]
278+
// the tree will look like this:
279+
// Unapply[t](pats)(implicits) : T[t @ t]
280+
// and the binds will be found in the type tree instead
281+
// Test case is pos-macros/i15971
282+
val tptBinds = getBinds(Set.empty[TypeSymbol], tpt)
275283
val binds: Set[TypeSymbol] = pat match {
276-
case UnApply(TypeApply(_, tpts), _, _) => getBinds(Set.empty[TypeSymbol], tpts)
277-
case _ => getBinds(Set.empty[TypeSymbol], tpt)
284+
case UnApply(TypeApply(_, tpts), _, _) =>
285+
getBinds(Set.empty[TypeSymbol], tpts) ++ tptBinds
286+
case _ => tptBinds
278287
}
279288

280289
val extractBindVariance = new TypeAccumulator[TypeBindsMap] {

tests/pos-macros/i15971.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
sealed trait A
2+
case class B[T](x: T) extends A
3+
4+
object Test {
5+
inline def fun(x: A): Int = inline x match {
6+
case B(x1): B[t] => 0
7+
}
8+
9+
@main def main() =
10+
val x = B(0)
11+
fun(x)
12+
}

0 commit comments

Comments
 (0)