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 defining AnyVal values in REPL (due to java.lang.ClassNotFoundException) #17557

Closed
j-mie6 opened this issue May 22, 2023 · 2 comments
Labels
itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label

Comments

@j-mie6
Copy link

j-mie6 commented May 22, 2023

Compiler version

Version 3.2.2

Reproduction steps

Start a Scala 3 REPL session:

$ scala -classpath "$(cs fetch -p com.github.j-mie6::parsley:4.2.10)"

In this session:

scala> import parsley.Parsley.*
scala> val p = pure(6)

Output (click arrow to expand)

Exception in thread "main" java.lang.ClassNotFoundException: Parsley
        at dotty.tools.repl.AbstractFileClassLoader.findClass(AbstractFileClassLoader.scala:51)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
        at dotty.tools.repl.AbstractFileClassLoader.loadClass(AbstractFileClassLoader.scala:57)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:467)
        at dotty.tools.repl.Rendering.rewrapValueClass(Rendering.scala:135)
        at dotty.tools.repl.Rendering.$anonfun$4(Rendering.scala:114)
        at scala.Option.flatMap(Option.scala:283)
        at dotty.tools.repl.Rendering.valueOf(Rendering.scala:114)
        at dotty.tools.repl.Rendering.renderVal(Rendering.scala:157)
        at dotty.tools.repl.ReplDriver.$anonfun$7(ReplDriver.scala:365)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:333)
        at dotty.tools.repl.ReplDriver.extractAndFormatMembers$1(ReplDriver.scala:371)
        at dotty.tools.repl.ReplDriver.renderDefinitions$$anonfun$2(ReplDriver.scala:403)
        at scala.Option.map(Option.scala:242)
        at dotty.tools.repl.ReplDriver.renderDefinitions(ReplDriver.scala:409)
        at dotty.tools.repl.ReplDriver.compile$$anonfun$2(ReplDriver.scala:307)
        at scala.util.Either.fold(Either.scala:189)
        at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:323)
        at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:248)
        at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:168)
        at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:171)
        at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:191)
        at dotty.tools.repl.ReplDriver.runBody$$anonfun$1(ReplDriver.scala:179)
        at dotty.tools.runner.ScalaClassLoader$.asContext(ScalaClassLoader.scala:80)
        at dotty.tools.repl.ReplDriver.runBody(ReplDriver.scala:179)
        at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:171)
        at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:133)
        at dotty.tools.repl.Main$.main(Main.scala:7)
        at dotty.tools.MainGenericRunner$.run$1(MainGenericRunner.scala:193)
        at dotty.tools.MainGenericRunner$.process(MainGenericRunner.scala:270)
        at dotty.tools.MainGenericRunner$.main(MainGenericRunner.scala:281)
        at dotty.tools.MainGenericRunner.main(MainGenericRunner.scala)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at coursier.bootstrap.launcher.a.a(Unknown Source)
        at coursier.bootstrap.launcher.Launcher.main(Unknown Source)

Additional information

This is not a problem with the Scala 2.13 REPL. Use of a lazy val prevents the crash:

scala> import parsley.Parsley.*
scala> lazy val p = pure(6)
scala> p.parse("") // works!
scala> p               // crashes as above!

However, if p is printed at any point this causes the crash. For context, the class in question is defined as:

final class Parsley[+A] private [parsley] (private [parsley] val internal: frontend.LazyParsley[A]) extends AnyVal

Making it an AnyVal class (this appears to be referenced within the stack trace).

With Scala 2.13 evaluating p in the REPL produces the output:

val p:  parsley.Parsley[Int] = parsley.Parsley@4392362c
@j-mie6 j-mie6 added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels May 22, 2023
@som-snytt
Copy link
Contributor

I asked tardily in the chat room whether it was tried on nightly. Here is local publication that works.

Apparently, dotty is still one step ahead of us.

➜  snips scala-cli --scala 3.3.1-RC1-bin-SNAPSHOT --dependency com.github.j-mie6::parsley:4.2.10
Welcome to Scala 3.3.1-RC1-bin-SNAPSHOT-git-fe08f5f (20.0.1, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> import parsley.*, character.*, combinator.*, Parsley.*

scala> val rps: Parsley[List[Char]] = string("recordParserString") *> space *> some(noneOf('\n')) <* optional(char('\n'))
val rps: parsley.Parsley[List[Char]] = parsley.Parsley@1002b06d

scala> rps
val res0: parsley.Parsley[List[Char]] = parsley.Parsley@1002b06d

scala> val p = pure(6)
val p: parsley.Parsley[Int] = parsley.Parsley@3922b297

scala> p.parse("")
val res1: parsley.Result[String, Int] = Success(6)

scala> p
val res2: parsley.Parsley[Int] = parsley.Parsley@3922b297

scala>

@som-snytt
Copy link
Contributor

231f9ab

Duplicates #16322

So the knock-on effect of delayed releases is duplicate ticketing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label
Projects
None yet
Development

No branches or pull requests

2 participants