Skip to content

Extension method on Java class fails in runtime #12537

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
prolativ opened this issue May 20, 2021 · 3 comments · Fixed by #14881
Closed

Extension method on Java class fails in runtime #12537

prolativ opened this issue May 20, 2021 · 3 comments · Fixed by #14881

Comments

@prolativ
Copy link
Contributor

Compiler version

3.0.0

Minimized code

String.nn

Output (click arrow to expand)

Exception in thread "main" java.lang.NoClassDefFoundError: java/lang/String$
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.getDeclaredMethods(Class.java:1975)
	at dotty.tools.repl.Rendering.valueOf(Rendering.scala:102)
	at dotty.tools.repl.Rendering.renderVal(Rendering.scala:141)
	at dotty.tools.repl.ReplDriver.$anonfun$13(ReplDriver.scala:323)
	at scala.collection.immutable.List.flatMap(List.scala:293)
	at scala.collection.immutable.List.flatMap(List.scala:79)
	at dotty.tools.repl.ReplDriver.extractAndFormatMembers$1(ReplDriver.scala:323)
	at dotty.tools.repl.ReplDriver.renderDefinitions$$anonfun$2(ReplDriver.scala:346)
	at scala.Option.map(Option.scala:242)
	at dotty.tools.repl.ReplDriver.renderDefinitions(ReplDriver.scala:349)
	at dotty.tools.repl.ReplDriver.compile$$anonfun$2(ReplDriver.scala:268)
	at scala.util.Either.fold(Either.scala:189)
	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:285)
	at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:212)
	at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:145)
	at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:148)
	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:167)
	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:148)
	at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:114)
	at dotty.tools.repl.Main$.main(Main.scala:6)
	at dotty.tools.repl.Main.main(Main.scala)
Caused by: java.lang.ClassNotFoundException: java.lang.String$
	at dotty.tools.repl.AbstractFileClassLoader.findClass$$anonfun$1(AbstractFileClassLoader.scala:44)
	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.AbstractFileClassLoader.findClass(AbstractFileClassLoader.scala:46)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	at dotty.tools.repl.AbstractFileClassLoader.loadClass(AbstractFileClassLoader.scala:55)
	... 23 more

Expectation

This should not throw an exception.

@OlivierBlanvillain
Copy link
Contributor

OlivierBlanvillain commented May 20, 2021

Minimized (without inline):

extension [T](x: T) def ext: T = x
def foo = String.ext

FWIW -Ycheck:all catches the anomaly after erasure:

*** error while checking /home/olivier/workspace/dotty/tests/run/12537.scala after phase erasure ***                         
exception occurred while compiling /home/olivier/workspace/dotty/tests/run/12537.scala                                       
Exception in thread "main" java.lang.AssertionError: assertion failed: Java class can't be used as value: Ident(String)

@griggt
Copy link
Contributor

griggt commented May 20, 2021

Same stack trace as #12346

@bishabosha
Copy link
Member

seems like an implicit conversion/extension should never be applied to a module if it is java defined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants