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

Compiler crash on irrefutable unapplySeq #6849

Closed
liufengyun opened this issue Jul 15, 2019 · 1 comment · Fixed by #6850
Closed

Compiler crash on irrefutable unapplySeq #6849

liufengyun opened this issue Jul 15, 2019 · 1 comment · Fixed by #6850

Comments

@liufengyun
Copy link
Contributor

@liufengyun liufengyun commented Jul 15, 2019

Discovered when working on #6490

minimized code

final class Foo(val value: Int)

object Foo {
  def unapplySeq(foo: Foo): Seq[Int] = List(foo.value)
}

object Test {
  def main(args: Array[String]): Unit = {
    (new Foo(3)) match {
      case Foo(x, _: _*) =>
        assert(x == 3)
    }
  }
}
Stack trace
exception occurred while compiling tests/run/i6490.scala
java.lang.AssertionError: assertion failed while compiling tests/run/i6490.scala
Exception in thread "main" java.lang.AssertionError: assertion failed
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:15)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.unapplyPlan$3$$anonfun$2(PatternMatcher.scala:332)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.letAbstract(PatternMatcher.scala:100)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.unapplyPlan$1(PatternMatcher.scala:350)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.patternPlan(PatternMatcher.scala:377)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.caseDefPlan(PatternMatcher.scala:413)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.matchPlan$$anonfun$2$$anonfun$1(PatternMatcher.scala:420)
	at scala.collection.immutable.List.$anonfun$foldRight$1(List.scala:408)
	at scala.collection.immutable.List.foldRight(List.scala:89)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.matchPlan$$anonfun$1(PatternMatcher.scala:420)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.letAbstract(PatternMatcher.scala:100)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.matchPlan(PatternMatcher.scala:421)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.translateMatch(PatternMatcher.scala:979)
	at dotty.tools.dotc.transform.PatternMatcher.transformMatch(PatternMatcher.scala:35)
	at dotty.tools.dotc.transform.MegaPhase.goMatch(MegaPhase.scala:746)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:345)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:396)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:287)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:396)
	at dotty.tools.dotc.transform.MegaPhase.mapDefDef$1(MegaPhase.scala:245)
	at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:248)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:394)
	at dotty.tools.dotc.transform.MegaPhase.transformStat$2(MegaPhase.scala:404)
	at dotty.tools.dotc.transform.MegaPhase.$anonfun$1(MegaPhase.scala:409)
	at scala.collection.immutable.List.mapConserve(List.scala:179)
	at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:409)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:339)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:396)
	at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:251)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:394)
	at dotty.tools.dotc.transform.MegaPhase.transformStat$2(MegaPhase.scala:404)
	at dotty.tools.dotc.transform.MegaPhase.$anonfun$1(MegaPhase.scala:409)
	at scala.collection.immutable.List.mapConserve(List.scala:179)
	at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:409)
	at dotty.tools.dotc.transform.MegaPhase.mapPackage$1(MegaPhase.scala:356)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:359)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:396)
	at dotty.tools.dotc.transform.MegaPhase.transformUnit(MegaPhase.scala:415)
	at dotty.tools.dotc.transform.MegaPhase.run(MegaPhase.scala:427)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:316)
	at scala.collection.immutable.List.map(List.scala:286)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:318)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:158)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
	at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33)
	at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:198)
	at dotty.tools.dotc.Run.runPhases$5(Run.scala:170)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:178)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:102)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:185)
	at dotty.tools.dotc.Run.compileSources(Run.scala:120)
	at dotty.tools.dotc.Run.compile(Run.scala:104)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:34)
	at dotty.tools.dotc.Driver.process(Driver.scala:172)
	at dotty.tools.dotc.Driver.process(Driver.scala:141)
	at dotty.tools.dotc.Driver.process(Driver.scala:153)
	at dotty.tools.dotc.Driver.main(Driver.scala:180)
	at dotty.tools.dotc.Main.main(Main.scala)

note

The following code compiles and runs without issue:

final class Foo(val value: Int)

object Foo {
  def unapplySeq(foo: Foo): (Int, Seq[Int]) = (foo.value, Nil)
}

object Test {
  def main(args: Array[String]): Unit = {
    (new Foo(3)) match {
      case Foo(x, _: _*) =>
        assert(x == 3)
    }
  }
}
@alexknvl

This comment has been minimized.

Copy link

@alexknvl alexknvl commented Dec 13, 2019

A slightly different example of the same bug:

object A {
    def unapplySeq(a: Any): Seq[_] = ""
}
def unapply(x: Any) = x match { case A() => }
liufengyun added a commit to dotty-staging/dotty that referenced this issue Dec 13, 2019
liufengyun added a commit to dotty-staging/dotty that referenced this issue Dec 13, 2019
liufengyun added a commit to dotty-staging/dotty that referenced this issue Jan 14, 2020
nicolasstucki added a commit that referenced this issue Jan 16, 2020
Fix #6849: support irrefutable sequence match
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.