Skip to content

Commit 8c69ca0

Browse files
committed
Fix errors in explicit type annotations in inline match cases
Previusly, Unapply trees would have type bindings generated inside their body and this was the only case handled in InlineReducer. However, this 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.
1 parent 1ae85eb commit 8c69ca0

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-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

Whitespace-only changes.

0 commit comments

Comments
 (0)