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

REPL regression with instantiating class instances from the scala.concurrent.duration package #16322

Closed
ghost opened this issue Nov 11, 2022 · 2 comments · Fixed by #16393
Closed
Labels
area:repl itype:bug itype:crash regression This worked in a previous version but doesn't anymore
Milestone

Comments

@ghost
Copy link

ghost commented Nov 11, 2022

Compiler version

3.2.1

Minimized code

Open a Scala 3.2.1 REPL:

Welcome to Scala 3.2.1 (17.0.5, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                        
scala> new scala.concurrent.duration.DurationInt(5)

Output

Exception in thread "main" java.lang.ClassNotFoundException: package$DurationInt
	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:127)
	at dotty.tools.repl.Rendering.$anonfun$4(Rendering.scala:106)
	at scala.Option.flatMap(Option.scala:283)
	at dotty.tools.repl.Rendering.valueOf(Rendering.scala:106)
	at dotty.tools.repl.Rendering.renderVal(Rendering.scala:149)
	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)

Same error happens if new is not used.

Expectation

Scala 3.2.0 REPL:

Welcome to Scala 3.2.0 (17.0.5, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                        
scala> new scala.concurrent.duration.DurationInt(5)

Output:

val res0: scala.concurrent.duration.package.DurationInt = 5

Although, the result is also weird, there's a mention of scala.concurrent.duration.package.DurationInt, which is not the same fully qualified name. As far as I can tell, this behavior is consistent in Scala 3.1.3 too. I did not check older versions.

Edit:

Scala 2.13.10 reports the same value as:

val res0: concurrent.duration.DurationInt = scala.concurrent.duration.package$DurationInt@5

The mention of package might just be down to the bytecode encoding and might be completely fine.

@ghost ghost added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 11, 2022
@KacperFKorban KacperFKorban added area:repl regression This worked in a previous version but doesn't anymore and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 11, 2022
mutcianm pushed a commit to JetBrains/intellij-scala that referenced this issue Nov 14, 2022
…20734

- The lines that instantiate classes from scala.concurrent.duration have been removed due to scala/scala3#16322. A test will be added for that specifically.
- The presentation of some methods has been changed in the platform, to show a `:` instead of `=>`.
mutcianm pushed a commit to JetBrains/intellij-scala that referenced this issue Nov 14, 2022
mutcianm pushed a commit to JetBrains/intellij-scala that referenced this issue Nov 14, 2022
…20734

- The lines that instantiate classes from scala.concurrent.duration have been removed due to scala/scala3#16322. A test will be added for that specifically.
- The presentation of some methods has been changed in the platform, to show a `:` instead of `=>`.
mutcianm pushed a commit to JetBrains/intellij-scala that referenced this issue Nov 14, 2022
@SethTisue
Copy link
Member

SethTisue commented Nov 22, 2022

Note that the problem isn't in the instantiation itself:

scala> (new scala.concurrent.duration.DurationInt(5)): Any
val res0: Any = scala.concurrent.duration.package$DurationInt@5

but in the REPL code for type-driven printing of values (as obvious anyway in the stack trace: dotty.tools.repl.Rendering).

It seems from #16387 that the package-object angle isn't relevant; it's a value-class thing. But maybe it's relevant that neither value-class is top level.

Dale has a suspect: #15545 . But it does have a test of an inner value class, so why are these failure cases different?

@SethTisue
Copy link
Member

SethTisue commented Nov 22, 2022

Ah, it's because you need a package declaration; it needn't be an inner class.

I think this is the minimal reproducer:

package p
class D(val n: Int) extends AnyVal

and then in the REPL, new p.D(5) or even just null.asInstanceOf[p.D]

(We should still also include a test that has an inner class and a package, though, since we're slinging JVM-level class names and inner classes is an easy area for that to go wrong.)

smarter added a commit that referenced this issue Dec 9, 2022
By fixing `Rendering`'s `rewrapValueClass` to use the fully qualified
class name

Sequel to #15545

Fixes #16322
Fixes #16387
@Kordyjan Kordyjan modified the milestone: Future versions Dec 12, 2022
@Kordyjan Kordyjan added this to the 3.3.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:repl itype:bug itype:crash regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants