Skip to content

Compiler crashes when unapply + Selectable are used #24168

@road21

Description

@road21

Compiler version

3.7.3

Minimized code

trait Generic extends Selectable:
  def applyDynamic(name: String)(args: Any*): Any = ()

val foo: Generic {
  def unapply(x: Int): Option[Unit]
} = new Generic:
  def unapply(x: Int): Option[Unit] = Some(()) // implementation doesn't matter

42 match
  case foo(()) => println("lol")

Output (click arrow to expand)

Error: java.lang.AssertionError: assertion failed
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
        at dotty.tools.dotc.core.Decorators$.assertingErrorsReported(Decorators.scala:299)
        at dotty.tools.dotc.typer.Applications.loop$1(Applications.scala:1699)
        at dotty.tools.dotc.typer.Applications.unapplyImplicits$1(Applications.scala:1701)
        at dotty.tools.dotc.typer.Applications.typedUnApply(Applications.scala:1751)
        at dotty.tools.dotc.typer.Applications.typedUnApply$(Applications.scala:470)
        at dotty.tools.dotc.typer.Typer.typedUnApply(Typer.scala:155)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3671)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3759)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3836)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3841)
        at dotty.tools.dotc.typer.Typer.typedPattern(Typer.scala:3973)
        at dotty.tools.dotc.typer.Typer.typedCase(Typer.scala:2321)
        at dotty.tools.dotc.typer.Typer.typedCases$$anonfun$1(Typer.scala:2247)
        at dotty.tools.dotc.core.Decorators$.loop$1(Decorators.scala:99)
        at dotty.tools.dotc.core.Decorators$.mapconserve(Decorators.scala:115)
        at dotty.tools.dotc.typer.Typer.typedCases(Typer.scala:2246)
        at dotty.tools.dotc.typer.Typer.$anonfun$41(Typer.scala:2229)
        at dotty.tools.dotc.typer.Applications.harmonic(Applications.scala:2738)
        at dotty.tools.dotc.typer.Applications.harmonic$(Applications.scala:470)
        at dotty.tools.dotc.typer.Typer.harmonic(Typer.scala:155)
        at dotty.tools.dotc.typer.Typer.typedMatchFinish(Typer.scala:2229)
        at dotty.tools.dotc.typer.Typer.typedMatch(Typer.scala:2157)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3686)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3759)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3836)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3841)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3890)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3909)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3328)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3659)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3663)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3758)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3836)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3841)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3863)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3909)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3461)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3705)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3759)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3836)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3841)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3952)
        at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:510)
        at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:53)
        at dotty.tools.dotc.typer.TyperPhase.$anonfun$4(TyperPhase.scala:99)
        at scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479)
        at scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:583)
        at scala.collection.immutable.List.prependedAll(List.scala:152)
        at scala.collection.immutable.List$.from(List.scala:685)
        at scala.collection.immutable.List$.from(List.scala:682)
        at scala.collection.IterableOps$WithFilter.map(Iterable.scala:900)
        at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:98)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:380)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1324)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:373)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$2(Run.scala:420)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$adapted$1(Run.scala:420)
        at scala.Function0.apply$mcV$sp(Function0.scala:42)
        at dotty.tools.dotc.Run.showProgress(Run.scala:482)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:420)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:432)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:432)
        at dotty.tools.dotc.Run.compileSources(Run.scala:319)
        at dotty.tools.dotc.Run.compile(Run.scala:304)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
        at dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:141)
        at dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
        at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.compileSources$1(BloopHighLevelCompiler.scala:148)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$9(BloopHighLevelCompiler.scala:181)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$1(BloopHighLevelCompiler.scala:73)
        at bloop.tracing.NoopTracer$.trace(BraveTracer.scala:53)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.timed$1(BloopHighLevelCompiler.scala:72)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$8(BloopHighLevelCompiler.scala:181)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at monix.eval.internal.TaskRunLoop$.startFull(TaskRunLoop.scala:81)
        at monix.eval.internal.TaskRestartCallback.syncOnSuccess(TaskRestartCallback.scala:101)
        at monix.eval.internal.TaskRestartCallback.onSuccess(TaskRestartCallback.scala:74)
        at monix.eval.internal.TaskExecuteOn$AsyncRegister$$anon$1.run(TaskExecuteOn.scala:71)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.compute(ForkJoinTask.java:1726)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.compute(ForkJoinTask.java:1717)
        at java.base/java.util.concurrent.ForkJoinTask$InterruptibleTask.exec(ForkJoinTask.java:1641)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1460)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2036)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:189)

Expectation

For scala.reflect.Selecatble we get compiler error Structural unapply is not supported

//> using scala 3.7.3

val foo2 = new scala.reflect.Selectable {
  def apply(x: Int): Unit = ()
  def unapply(x: Int): Option[Unit] = Some(())
}

foo2(42)

42 match
  case foo2(()) => println("lol")

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions