Skip to content

compiler crash "exception while typing" ... "scala.MatchError"... #11466

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

Closed
flomebul opened this issue Feb 18, 2021 · 1 comment · Fixed by #11478
Closed

compiler crash "exception while typing" ... "scala.MatchError"... #11466

flomebul opened this issue Feb 18, 2021 · 1 comment · Fixed by #11478
Assignees
Labels
area:implicits related to implicits itype:bug
Milestone

Comments

@flomebul
Copy link
Contributor

flomebul commented Feb 18, 2021

Compiler version

scala version 3.0.0-RC1

Minimized code

In the following code, the line val m = new Node("Alice") is supposed to give a compile error, but a compiler crash is obtained.

open class GraphDB[Id]:
  class Node private[GraphDB](val id: Id)
end GraphDB

import org.scalatest.flatspec.AnyFlatSpec

object GraphDBSpec extends AnyFlatSpec:
  object graph extends GraphDB[String]
  import graph.*
  val m = new Node("Alice")
end GraphDBSpec

Output

exception while typing asuivre.GraphDBSpec.convertToEqualizer[Object](
  new asuivre.GraphDBSpec.graph.Node
)[Object]("Alice") of class class dotty.tools.dotc.ast.Trees$Apply # -1
exception while typing def m: asuivre.GraphDBSpec.Equalizer[Object] = 
  asuivre.GraphDBSpec.convertToEqualizer[Object](
    new asuivre.GraphDBSpec.graph.Node
  )[Object]("Alice") of class class dotty.tools.dotc.ast.Trees$DefDef # -1
exception while typing @scala.annotation.internal.SourceFile(
  "asuivre/src/main/scala/asuivre/Issue99990.scala"
) final module class GraphDBSpec$() extends org.scalatest.flatspec.AnyFlatSpec()
   {
  private def writeReplace(): AnyRef = 
    new scala.runtime.ModuleSerializationProxy(classOf[asuivre.GraphDBSpec.type]
      )
  final lazy module val graph: asuivre.GraphDBSpec.graph$ = 
    new asuivre.GraphDBSpec.graph$()
  final module class graph$() extends asuivre.GraphDB[String]() {
    private def writeReplace(): AnyRef = 
      new scala.runtime.ModuleSerializationProxy(
        classOf[asuivre.GraphDBSpec.graph.type]
      )
  }
  def m: asuivre.GraphDBSpec.Equalizer[Object] = 
    asuivre.GraphDBSpec.convertToEqualizer[Object](
      new asuivre.GraphDBSpec.graph.Node
    )[Object]("Alice")
} of class class dotty.tools.dotc.ast.Trees$TypeDef # -1
exception while typing package asuivre {
  @scala.annotation.internal.SourceFile(
    "asuivre/src/main/scala/asuivre/Issue99990.scala"
  ) open class GraphDB[Id]() extends Object() {
    private type Id
    class Node private[GraphDB](id: Id) extends Object() {
      def id: Id
      private val $outer: asuivre.GraphDB[Id]
      final def asuivre$GraphDB$Node$$$outer: asuivre.GraphDB[Id] = 
        Node.this.$outer
    }
  }
  final lazy module val GraphDBSpec: asuivre.GraphDBSpec$ = 
    new asuivre.GraphDBSpec$()
  @scala.annotation.internal.SourceFile(
    "asuivre/src/main/scala/asuivre/Issue99990.scala"
  ) final module class GraphDBSpec$() extends org.scalatest.flatspec.AnyFlatSpec
    (
  ) {
    private def writeReplace(): AnyRef = 
      new scala.runtime.ModuleSerializationProxy(
        classOf[asuivre.GraphDBSpec.type]
      )
    final lazy module val graph: asuivre.GraphDBSpec.graph$ = 
      new asuivre.GraphDBSpec.graph$()
    final module class graph$() extends asuivre.GraphDB[String]() {
      private def writeReplace(): AnyRef = 
        new scala.runtime.ModuleSerializationProxy(
          classOf[asuivre.GraphDBSpec.graph.type]
        )
    }
    def m: asuivre.GraphDBSpec.Equalizer[Object] = 
      asuivre.GraphDBSpec.convertToEqualizer[Object](
        new asuivre.GraphDBSpec.graph.Node
      )[Object]("Alice")
  }
} of class class dotty.tools.dotc.ast.Trees$PackageDef # -1
[info] exception occurred while compiling D:\Users\Luc\Documents\Home\ProjCode\Scala_3.0\asuivre\src\main\scala\asuivre\Issue99990.scala
scala.MatchError: Apply(TypeApply(Ident(convertToEqualizer),List(TypeTree[TypeVar(TypeParamRef(T) -> TypeRef(ThisType(TypeRef(NoPrefix,module class lang)),class Object))])),List(New(TypeTree[TypeRef(TermRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class asuivre)),module class GraphDBSpec$)),object graph),class Node)]))) (of class dotty.tools.dotc.ast.Trees$Apply) while compiling D:\Users\Luc\Documents\Home\ProjCode\Scala_3.0\asuivre\src\main\scala\asuivre\Issue99990.scala
[error] ## Exception when compiling 5 sources to D:\Users\Luc\Documents\Home\ProjCode\Scala_3.0\asuivre\target\scala-3.0.0-RC1\classes
[error] scala.MatchError: Apply(TypeApply(Ident(convertToEqualizer),List(TypeTree[TypeVar(TypeParamRef(T) -> TypeRef(ThisType(TypeRef(NoPrefix,module class lang)),class Object))])),List(New(TypeTree[TypeRef(TermRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class asuivre)),module class GraphDBSpec$)),object graph),class Node)]))) (of class dotty.tools.dotc.ast.Trees$Apply)
[error] dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.outerArg$1(ExplicitOuter.scala:381)
[error] dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.args$extension(ExplicitOuter.scala:385)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:824)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2593)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2655)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2720)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2724)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2840)
[error] dotty.tools.dotc.typer.Typer.$anonfun$35(Typer.scala:2080)
[error] dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:223)
[error] dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2080)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:929)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2570)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2654)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2720)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2724)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2746)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2796)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1037)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2226)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1026)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2581)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2585)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2654)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2720)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2724)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2746)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2796)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1037)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2378)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2626)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2655)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2720)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2724)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2840)
[error] dotty.tools.dotc.transform.Erasure.run(Erasure.scala:124)
[error] dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:303)
[error] scala.collection.immutable.List.map(List.scala:246)
[error] dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:304)
[error] dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:205)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
[error] dotty.tools.dotc.Run.runPhases$5(Run.scala:215)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:223)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:230)
[error] dotty.tools.dotc.Run.compileSources(Run.scala:166)
[error] dotty.tools.dotc.Run.compile(Run.scala:150)
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:39)
[error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88)
[error] dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
[error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:92)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:186)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:241)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:176)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:157)
[error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:157)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:204)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:573)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:573)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:174)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:172)
[error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:459)
[error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
[error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:261)
[error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:414)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:499)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:401)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:166)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:573)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:491)
[error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420)
[error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2177)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2134)
[error] sbt.internal.io.Retry$.apply(Retry.scala:40)
[error] sbt.internal.io.Retry$.apply(Retry.scala:23)
[error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2130)
[error] scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error] sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error] sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error] sbt.Execute.work(Execute.scala:291)
[error] sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error] java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error] java.base/java.lang.Thread.run(Thread.java:834)
[error]            
[error] stack trace is suppressed; run last asuivre / Compile / compileIncremental for the full output
[error] (asuivre / Compile / compileIncremental) scala.MatchError: Apply(TypeApply(Ident(convertToEqualizer),List(TypeTree[TypeVar(TypeParamRef(T) -> TypeRef(ThisType(TypeRef(NoPrefix,module class lang)),class Object))])),List(New(TypeTree[TypeRef(TermRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class asuivre)),module class GraphDBSpec$)),object graph),class Node)]))) (of class dotty.tools.dotc.ast.Trees$Apply)
[error] Total time: 9 s, completed 18 f├®vr. 2021 á 23:20:30
liufengyun added a commit to dotty-staging/dotty that referenced this issue Feb 19, 2021
@liufengyun liufengyun self-assigned this Feb 19, 2021
@griggt
Copy link
Contributor

griggt commented Feb 19, 2021

Self-contained minimization (without ScalaTest dependency):

import scala.language.implicitConversions

trait TripleEqualsSupport:
  class Equalizer[L](val leftSide: L)
  def convertToEqualizer[T](left: T): Equalizer[T]

trait TripleEquals extends TripleEqualsSupport:
  implicit override def convertToEqualizer[T](left: T): Equalizer[T] = new Equalizer(left)

class GraphDB[Id]:
  class Node private[GraphDB](val id: Id)

object GraphDBSpec extends TripleEquals:
  object graph extends GraphDB[String]
  import graph.Node
  val m = new Node("Alice")

liufengyun added a commit to dotty-staging/dotty that referenced this issue Feb 19, 2021
@liufengyun liufengyun added area:implicits related to implicits itype:bug labels Feb 22, 2021
nicolasstucki added a commit that referenced this issue Feb 24, 2021
Fix #11466: disallow implicit conversion for <init>
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:implicits related to implicits itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants