Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors in explicit type annotations in inline match cases #16257

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 12 additions & 0 deletions tests/pos-macros/i15971.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sealed trait A
case class B[T](x: T) extends A

object Test {
inline def fun(x: A): Int = inline x match {
case B(x1): B[t] => 0
}

@main def main() =
val x = B(0)
fun(x)
}