From 8c69ca078bd0d2c9fb0655a844712b6dfc9229af Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Thu, 27 Oct 2022 15:13:56 +0200 Subject: [PATCH] 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. --- .../dotty/tools/dotc/inlines/InlineReducer.scala | 15 ++++++++++++--- tests/pos-macros/i15971.scala | 0 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 tests/pos-macros/i15971.scala diff --git a/compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala b/compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala index debf51872d5a..460d0a61c252 100644 --- a/compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala +++ b/compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala @@ -269,12 +269,21 @@ class InlineReducer(inliner: Inliner)(using Context): } } - // Extractors contain Bind nodes in type parameter lists, the tree looks like this: + // Extractors can contain Bind nodes in type parameter lists, + // for that case tree looks like this: // UnApply[t @ t](pats)(implicits): T[t] // Test case is pos/inline-caseclass.scala. + // Alternatively, for explicitly specified type binds in type annotations like in + // case A(B): A[t] + // the tree will look like this: + // Unapply[t](pats)(implicits) : T[t @ t] + // and the binds will be found in the type tree instead + // Test case is pos-macros/i15971 + val tptBinds = getBinds(Set.empty[TypeSymbol], tpt) val binds: Set[TypeSymbol] = pat match { - case UnApply(TypeApply(_, tpts), _, _) => getBinds(Set.empty[TypeSymbol], tpts) - case _ => getBinds(Set.empty[TypeSymbol], tpt) + case UnApply(TypeApply(_, tpts), _, _) => + getBinds(Set.empty[TypeSymbol], tpts) ++ tptBinds + case _ => tptBinds } val extractBindVariance = new TypeAccumulator[TypeBindsMap] { diff --git a/tests/pos-macros/i15971.scala b/tests/pos-macros/i15971.scala new file mode 100644 index 000000000000..e69de29bb2d1