scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.72k stars 1.04k forks source link

compiler crash "dotty.tools.dotc.core.TypeError$$anon$1: due to previous compiler jars in classpath #19663

Open philwalk opened 4 months ago

philwalk commented 4 months ago

Compiler version

# scalac -version
Scala compiler version 3.4.0-RC4 -- Copyright 2002-2024, LAMP/EPFL

This turned out to be a function of the classpath. The minimum classpath for exhibiting the problem contains only the scala3-library_3-3.3.1.jar from a previous scala version. This seems less like a bug than an error message that is likely to be confusing.

Minimized code

#!/usr/bin/env -S scala

object Main{
  def main(args: Array[String]): Unit = {
    val values = Seq.empty[String]
    val valcols: List[String] = values.size match {
      case 0 =>
        values.toList
      case num =>
        sys.error(s"bad list size: values[${values.toList}]\n")
    }
    valcols.mkString(",")
  }
}

Output (click arrow to expand)

```scala unhandled exception while running MegaPhase{protectedAccessors, extmethods, uncacheGivenAliases, elimByName, hoistSuperArgs, forwardDepChecks, specializeApplyMethods, tryCatchPatterns, patternMatcher} on C:\opt\ue\jsrc\dottyCrash.sc An unhandled exception was thrown in the compiler. Please file a crash report here: https://github.com/lampepfl/dotty/issues/new/choose For non-enriched exceptions, compile with -Yno-enrich-error-messages. while compiling: C:\opt\ue\jsrc\dottyCrash.sc during phase: MegaPhase{protectedAccessors, extmethods, uncacheGivenAliases, elimByName, hoistSuperArgs, forwardDepChecks, specializeApplyMethods, tryCatchPatterns, patternMatcher} mode: Mode(ImplicitsEnabled) library version: version 2.13.12 compiler version: version 3.4.0-RC4 settings: -classpath C:/Users/philwalk/AppData/Local/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.1/scala3-library_3-3.3.1.jar;C:/opt/scala3-3.4.0-RC4/lib/scala-library-2.13.12.jar;C:/opt/scala3-3.4.0-RC4/lib/scala3-library_3-3.4.0-RC4.jar;C:/opt/scala3-3.4.0-RC4/lib/scala-asm-9.6.0-scala-1.jar;C:/opt/scala3-3.4.0-RC4/lib/compiler-interface-1.9.3.jar;C:/opt/scala3-3.4.0-RC4/lib/scala3-interfaces-3.4.0-RC4.jar;C:/opt/scala3-3.4.0-RC4/lib/scala3-compiler_3-3.4.0-RC4.jar;C:/opt/scala3-3.4.0-RC4/lib/tasty-core_3-3.4.0-RC4.jar;C:/opt/scala3-3.4.0-RC4/lib/scala3-staging_3-3.4.0-RC4.jar;C:/opt/scala3-3.4.0-RC4/lib/scala3-tasty-inspector_3-3.4.0-RC4.jar;C:/opt/scala3-3.4.0-RC4/lib/jline-reader-3.19.0.jar;C:/opt/scala3-3.4.0-RC4/lib/jline-terminal-3.19.0.jar;C:/opt/scala3-3.4.0-RC4/lib/jline-terminal-jna-3.19.0.jar;C:/opt/scala3-3.4.0-RC4/lib/jna-5.3.1.jar -d C:\tmp\scala3-scripting5883074577800132427 Exception in thread "main" dotty.tools.dotc.core.TypeError$$anon$1: object caps does not have a member type Cap ```
Gedochao commented 3 months ago

Managed to reproduce at 9a5b9b4 with scala3-library for 3.3.1 directly adding the older scala3-library to the classpath is essential for reproduction.

exception occurred while typechecking repro.scala

  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/scala/scala3/issues/new/choose
  For non-enriched exceptions, compile with -Yno-enrich-error-messages.

     while compiling: repro.scala
        during phase: typer
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.12
    compiler version: version 3.5.0-RC1-bin-SNAPSHOT-nonbootstrapped-git-9a5b9b4
            settings: -classpath /Users/pchabelski/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.1/scala3-library_3-3.3.1.jar

Exception in thread "main" java.lang.ClassCastException: class dotty.tools.dotc.core.Symbols$NoSymbol$ cannot be cast to class dotty.tools.dotc.core.Symbols$ClassSymbol (dotty.tools.dotc.core.Symbols$NoSymbol$ and dotty.tools.dotc.core.Symbols$ClassSymbol are in unnamed module of loader 'app')
    at dotty.tools.dotc.core.Symbols$Symbol.asClass(Symbols.scala:191)
    at dotty.tools.dotc.core.Definitions.UnitClass(Definitions.scala:574)
    at dotty.tools.dotc.typer.ProtoTypes$Compatibility.disregardProto(ProtoTypes.scala:78)
    at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult(ProtoTypes.scala:99)
    at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult$(ProtoTypes.scala:29)
    at dotty.tools.dotc.typer.ProtoTypes$NoViewsAllowed$.constrainResult(ProtoTypes.scala:123)
    at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult(ProtoTypes.scala:120)
    at dotty.tools.dotc.typer.ProtoTypes$Compatibility.constrainResult$(ProtoTypes.scala:29)
    at dotty.tools.dotc.typer.ProtoTypes$NoViewsAllowed$.constrainResult(ProtoTypes.scala:123)
    at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:484)
    at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:795)
    at dotty.tools.dotc.typer.Applications$ApplyToTyped.<init>(Applications.scala:922)
    at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1139)
    at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:351)
    at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:120)
    at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:985)
    at dotty.tools.dotc.typer.Applications.realApply$1$$anonfun$2(Applications.scala:1068)
    at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3437)
    at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1079)
    at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1117)
    at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:351)
    at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:120)
    at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3137)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3221)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302)
    at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3413)
    at dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:2564)
    at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3116)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3220)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302)
    at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3324)
    at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3370)
    at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2947)
    at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3171)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3221)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302)
    at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3413)
    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:480)
    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:684)
    at scala.collection.immutable.List$.from(List.scala:681)
    at scala.collection.IterableOps$WithFilter.map(Iterable.scala:898)
    at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:100)
    at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:315)
    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:1323)
    at dotty.tools.dotc.Run.runPhases$1(Run.scala:337)
    at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:350)
    at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:360)
    at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
    at dotty.tools.dotc.Run.compileUnits(Run.scala:360)
    at dotty.tools.dotc.Run.compileSources(Run.scala:261)
    at dotty.tools.dotc.Run.compile(Run.scala:246)
    at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
    at dotty.tools.dotc.Driver.process(Driver.scala:196)
    at dotty.tools.dotc.Driver.process(Driver.scala:164)
    at dotty.tools.dotc.Driver.process(Driver.scala:176)
    at dotty.tools.dotc.Driver.main(Driver.scala:206)
    at dotty.tools.dotc.Main.main(Main.scala)

This makes it a valid bug, the compiler shouldn't crash on this. Although the steps are quite unusual.