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

Crash when both sequence and product match are possible #19219

Closed
SrTobi opened this issue Dec 7, 2023 · 1 comment · Fixed by #19277
Closed

Crash when both sequence and product match are possible #19219

SrTobi opened this issue Dec 7, 2023 · 1 comment · Fixed by #19277
Assignees
Labels
area:pattern-matching backlog No work planned on this by the core team for the time being. itype:bug itype:crash

Comments

@SrTobi
Copy link
Contributor

SrTobi commented Dec 7, 2023

Compiler version

3.3.1

Minimized code

object Test:
  class Custom extends scala.Product1[String]:
    def length: Int = ???
    def apply(i: Int): Boolean = ???
    def drop(n: Int): scala.Seq[Boolean] = ???
    def toSeq: scala.Seq[Boolean] = ???

    def canEqual(that: Any): Boolean = ???

    val _1: String = ???
    val _2: String = ???
    val _3: Seq[String] = ???

  class Unapplied:
    def isEmpty: Boolean = ???
    def get: Custom = ???

  object A:
    def unapplySeq(i: Int): Unapplied = ???

  val A(rest: _*) = 1

Note that the compiler doesn't crash, when A.unapplySeq returns Custom directly!

Output (click arrow to expand)

scala: ## Exception when compiling 8 sources to /home/<removed>/target/scala-3.3.1/classes
java.lang.AssertionError: assertion failed
scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
dotty.tools.dotc.transform.PatternMatcher$Translator.unapplyProductSeqPlan$1(PatternMatcher.scala:317)
dotty.tools.dotc.transform.PatternMatcher$Translator.$anonfun$11(PatternMatcher.scala:373)
dotty.tools.dotc.transform.PatternMatcher$Translator.letAbstract(PatternMatcher.scala:114)
dotty.tools.dotc.transform.PatternMatcher$Translator.unapplyPlan$1$$anonfun$1(PatternMatcher.scala:374)
dotty.tools.dotc.transform.PatternMatcher$Translator.letAbstract(PatternMatcher.scala:114)
dotty.tools.dotc.transform.PatternMatcher$Translator.unapplyPlan$1(PatternMatcher.scala:385)
dotty.tools.dotc.transform.PatternMatcher$Translator.patternPlan(PatternMatcher.scala:422)
dotty.tools.dotc.transform.PatternMatcher$Translator.caseDefPlan(PatternMatcher.scala:458)
dotty.tools.dotc.transform.PatternMatcher$Translator.matchPlan$$anonfun$1$$anonfun$1(PatternMatcher.scala:465)
scala.collection.immutable.List.foldRight(List.scala:352)
dotty.tools.dotc.transform.PatternMatcher$Translator.matchPlan$$anonfun$1(PatternMatcher.scala:465)
dotty.tools.dotc.transform.PatternMatcher$Translator.letAbstract(PatternMatcher.scala:114)
dotty.tools.dotc.transform.PatternMatcher$Translator.matchPlan(PatternMatcher.scala:466)
dotty.tools.dotc.transform.PatternMatcher$Translator.translateMatch(PatternMatcher.scala:1052)
dotty.tools.dotc.transform.PatternMatcher.transformMatch(PatternMatcher.scala:48)
dotty.tools.dotc.transform.MegaPhase.goMatch(MegaPhase.scala:804)
dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:371)
dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:442)
dotty.tools.dotc.transform.MegaPhase.mapValDef$1(MegaPhase.scala:239)
dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:244)
dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:440)
dotty.tools.dotc.transform.MegaPhase.loop$1(MegaPhase.scala:453)
dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:453)
dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:364)
dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:442)
dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:260)
dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:440)
dotty.tools.dotc.transform.MegaPhase.loop$1(MegaPhase.scala:453)
dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:453)
dotty.tools.dotc.transform.MegaPhase.mapPackage$1(MegaPhase.scala:384)
dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:387)
dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:442)
dotty.tools.dotc.transform.MegaPhase.loop$1(MegaPhase.scala:453)
dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:453)
dotty.tools.dotc.transform.MegaPhase.mapPackage$1(MegaPhase.scala:384)
dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:387)
dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:442)
dotty.tools.dotc.transform.MegaPhase.transformUnit(MegaPhase.scala:469)
dotty.tools.dotc.transform.MegaPhase.run(MegaPhase.scala:481)
dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:327)
scala.collection.immutable.List.map(List.scala:246)
dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:331)
dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:246)
scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1321)
dotty.tools.dotc.Run.runPhases$1(Run.scala:262)
dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:270)
dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:279)
dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
dotty.tools.dotc.Run.compileUnits(Run.scala:279)
dotty.tools.dotc.Run.compileSources(Run.scala:194)
dotty.tools.dotc.Run.compile(Run.scala:179)
dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88)
dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:193)
scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248)
sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183)
sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211)
sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534)
sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534)
sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:180)
sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:178)
sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:464)
sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:419)
sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506)
sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:406)
sbt.internal.inc.Incremental$.apply(Incremental.scala:172)
sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534)
sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488)
sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425)
sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
org.jetbrains.jps.incremental.scala.local.SbtCompiler.$anonfun$doCompile$3(SbtCompiler.scala:87)
scala.util.Try$.apply(Try.scala:210)
org.jetbrains.jps.incremental.scala.local.SbtCompiler.doCompile(SbtCompiler.scala:85)
org.jetbrains.jps.incremental.scala.local.SbtCompiler.compile(SbtCompiler.scala:17)
org.jetbrains.jps.incremental.scala.local.LocalServer.doCompile(LocalServer.scala:50)
org.jetbrains.jps.incremental.scala.local.LocalServer.compile(LocalServer.scala:28)
org.jetbrains.jps.incremental.scala.remote.Main$.compileLogic(Main.scala:210)
org.jetbrains.jps.incremental.scala.remote.Main$.$anonfun$handleCommand$1(Main.scala:193)
org.jetbrains.jps.incremental.scala.remote.Main$.decorated$1(Main.scala:180)
org.jetbrains.jps.incremental.scala.remote.Main$.handleCommand(Main.scala:190)
org.jetbrains.jps.incremental.scala.remote.Main$.serverLogic(Main.scala:163)
org.jetbrains.jps.incremental.scala.remote.Main$.nailMain(Main.scala:103)
org.jetbrains.jps.incremental.scala.remote.Main.nailMain(Main.scala)
jdk.internal.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.base/java.lang.reflect.Method.invoke(Method.java:568)
com.facebook.nailgun.NGSession.runImpl(NGSession.java:312)
com.facebook.nailgun.NGSession.run(NGSession.java:198)
           
@SrTobi SrTobi added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 7, 2023
@SrTobi
Copy link
Contributor Author

SrTobi commented Dec 7, 2023

Related issues: #19220, #19221

@mbovel mbovel added area:match-types area:pattern-matching and removed stat:needs triage Every issue needs to have an "area" and "itype" label area:match-types labels Dec 11, 2023
@odersky odersky removed their assignment Dec 12, 2023
@odersky odersky added the backlog No work planned on this by the core team for the time being. label Dec 12, 2023
@dwijnand dwijnand linked a pull request Dec 15, 2023 that will close this issue
@dwijnand dwijnand self-assigned this Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:pattern-matching backlog No work planned on this by the core team for the time being. itype:bug itype:crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants