Skip to content

Commit

Permalink
Fix errors in explicit type annotations in inline match cases
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jchyb committed Nov 13, 2022
1 parent 1ae85eb commit 8c69ca0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down
Empty file added tests/pos-macros/i15971.scala
Empty file.

0 comments on commit 8c69ca0

Please # to comment.