Skip to content

Fix Tasty reflect with varargs in unapply #4877

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

Merged
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
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,14 @@ class TastyImpl(val rootContext: Contexts.Context) extends scala.tasty.Tasty { s

object Unapply extends UnapplyExtractor {
def unapply(x: Pattern)(implicit ctx: Context): Option[(Term, List[Term], List[Pattern])] = x match {
case Trees.UnApply(fun, implicits, patterns) => Some((fun, implicits, patterns))
case Trees.Typed(Trees.UnApply(fun, implicits, patterns), _) => Some((fun, implicits, patterns))
case Trees.UnApply(fun, implicits, patterns) => Some((fun, implicits, effectivePatterns(patterns)))
case Trees.Typed(Trees.UnApply(fun, implicits, patterns), _) => Some((fun, implicits, effectivePatterns(patterns)))
case _ => None
}
private def effectivePatterns(patterns: List[Pattern]): List[Pattern] = patterns match {
case patterns0 :+ Trees.SeqLiteral(elems, _) => patterns0 ::: elems
case _ => patterns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that patterns only contain SeqLiteral?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the last one can one can have the SeqLiteral as only the last argument can be a varargs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. It's nice to have a link to test case here, as it's really difficult to figure out the test case
  2. The code fails to handle the following case:
case class D(b: B[_]*)

class Test {
  def f2(d: D) = d match {
    case D(a, b1, b2) => ()
  }
}

}
}

object Alternative extends AlternativeExtractor {
Expand Down
7 changes: 0 additions & 7 deletions compiler/test/dotc/run-decompilation.blacklist
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
# scala.MatchError: SeqLiteral in pattern
i3248.scala
t6541.scala

# Stackoverflow
t10594.scala

i4557.scala
i4557a.scala