Skip to content

NoSuchFieldError When Using enum Variants from the REPL #7410

Closed
@m-tabaza

Description

@m-tabaza

Here are the steps to reproduce this:

  • Create a new project using sbt new lampepfl/dotty.g8

  • Change the contents of src/main/scala/Main.scala to:

object Main {
  def main(args: Array[String]): Unit = {
    val a = E.A
    println(a)
  }
}

enum E {
  case A, B, C
}
  • In the REPL (sbt console) run:
scala> E.A

And you should get:

java.lang.NoSuchFieldError: A
        at rs$line$1$.<init>(rs$line$1:1)
        at rs$line$1$.<clinit>(rs$line$1)
        at rs$line$1.res0(rs$line$1)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at dotty.tools.repl.Rendering.$anonfun$3(Rendering.scala:72)
        at scala.Option.map(Option.scala:242)
        at dotty.tools.repl.Rendering.valueOf(Rendering.scala:72)
        at dotty.tools.repl.Rendering.renderVal(Rendering.scala:95)
        at dotty.tools.repl.ReplDriver.displayMembers$3$$anonfun$3(ReplDriver.scala:285)
        at scala.collection.immutable.List.map(List.scala:219)
        at scala.collection.immutable.List.map(List.scala:79)
        at dotty.tools.repl.ReplDriver.displayMembers$6(ReplDriver.scala:285)
        at dotty.tools.repl.ReplDriver.displayDefinitions$$anonfun$3$$anonfun$2(ReplDriver.scala:311)
        at scala.Option.map(Option.scala:242)
        at dotty.tools.repl.ReplDriver.displayDefinitions$$anonfun$1(ReplDriver.scala:311)
        at dotty.tools.dotc.core.Phases.atPhase$$anonfun$1(Phases.scala:35)
        at dotty.tools.dotc.core.Periods.atPhase(Periods.scala:25)
        at dotty.tools.dotc.core.Phases.atPhase(Phases.scala:35)
        at dotty.tools.dotc.core.Contexts$Context.atPhase(Contexts.scala:71)
        at dotty.tools.repl.ReplDriver.displayDefinitions(ReplDriver.scala:317)
        at dotty.tools.repl.ReplDriver.compile$$anonfun$2(ReplDriver.scala:241)
        at scala.util.Either.fold(Either.scala:189)
        at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:241)
        at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:193)
        at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:127)
        at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:130)
        at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:148)
        at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:130)
        at xsbt.ConsoleInterface.run(ConsoleInterface.java:52)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sbt.internal.inc.AnalyzingCompiler.call(AnalyzingCompiler.scala:237)
        at sbt.internal.inc.AnalyzingCompiler.console(AnalyzingCompiler.scala:199)
        at sbt.Console.console0$1(Console.scala:48)
        at sbt.Console.$anonfun$apply$2(Console.scala:51)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at sbt.util.InterfaceUtil$$anon$1.get(InterfaceUtil.scala:10)
        at sbt.TrapExit$App.run(TrapExit.scala:253)
        at java.lang.Thread.run(Thread.java:748)

This exception is thrown only in the REPL. Running the project with sbt run works just fine.

I'm using Dotty 0.19.0-RC1, SBT 1.2.7, and sbt-dotty plugin 0.3.4.

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