Skip to content

Generic extension method (<<<) crashes in REPL but non-generic version doesn't #6902

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
travisbrown opened this issue Jul 21, 2019 · 1 comment

Comments

@travisbrown
Copy link
Contributor

minimized code

given [A] { def (a: A) <<< : A = a }

1.<<<
Stack trace
java.lang.ClassFormatError: Method "<<<_of_A_given" in class rs$line$2$ has illegal signature "()Lrs$line$1$$$$_of_A_given;"
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:642)
	at dotty.tools.repl.AbstractFileClassLoader.findClass(AbstractFileClassLoader.scala:28)
	at dotty.tools.repl.AbstractFileClassLoader.loadClass(AbstractFileClassLoader.scala:32)
	at rs$line$2.res0(rs$line$2)
	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:497)
	at dotty.tools.repl.Rendering.$anonfun$3(Rendering.scala:57)
	at scala.Option.map(Option.scala:163)
	at dotty.tools.repl.Rendering.valueOf(Rendering.scala:57)
	at dotty.tools.repl.Rendering.renderVal(Rendering.scala:80)
	at dotty.tools.repl.ReplDriver.displayMembers$3$$anonfun$3(ReplDriver.scala:274)
	at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:237)
	at scala.collection.mutable.ResizableArray.foreach(ResizableArray.scala:62)
	at scala.collection.mutable.ResizableArray.foreach$(ResizableArray.scala:55)
	at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:49)
	at scala.collection.TraversableLike.map(TraversableLike.scala:237)
	at scala.collection.TraversableLike.map$(TraversableLike.scala:230)
	at scala.collection.AbstractTraversable.map(Traversable.scala:108)
	at dotty.tools.repl.ReplDriver.displayMembers$7(ReplDriver.scala:274)
	at dotty.tools.repl.ReplDriver.displayDefinitions$$anonfun$3$$anonfun$2(ReplDriver.scala:301)
	at scala.Option.map(Option.scala:163)
	at dotty.tools.repl.ReplDriver.displayDefinitions$$anonfun$1(ReplDriver.scala:301)
	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:306)
	at dotty.tools.repl.ReplDriver.compile$$anonfun$2(ReplDriver.scala:230)
	at scala.util.Either.fold(Either.scala:191)
	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:230)
	at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:182)
	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$$anonfun$2$$anonfun$1(ReplDriver.scala:143)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:62)
	at scala.Console$.withErr(Console.scala:196)
	at dotty.tools.repl.ReplDriver.withRedirectedOutput$$anonfun$1(ReplDriver.scala:143)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:62)
	at scala.Console$.withOut(Console.scala:167)
	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:143)
	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:497)
	at sbt.internal.inc.AnalyzingCompiler.call(AnalyzingCompiler.scala:248)
	at sbt.internal.inc.AnalyzingCompiler.console(AnalyzingCompiler.scala:210)
	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:23)
	at sbt.util.InterfaceUtil$$anon$1.get(InterfaceUtil.scala:10)
	at sbt.TrapExit$App.run(TrapExit.scala:257)
	at java.lang.Thread.run(Thread.java:745)

expectation

It seems like this should work, since the non-generic version is just fine:

scala> given { def (a: Int) <<< : Int = a }
// defined object <<<_of_Int_given

scala> 1.<<<
val res0: Int = 1
@travisbrown travisbrown changed the title Generic extension method (<<<) crashes but non-generic version doesn't Generic extension method (<<<) crashes in REPL but non-generic version doesn't Jul 21, 2019
smarter added a commit to dotty-staging/dotty that referenced this issue Jul 21, 2019
Name encoding does not kick in automatically for operator symbols which
appear in a prefix of a name, so the name `<<<_of_A_given` was kept as
is, which is problematic since `<` is not valid in method names on the
JVM (in `i6902.scala`, `<<<<` runs fine even before this change, because
monomorphic givens are implemented as vals, not defs).

Having to remember to call `avoidIllegalChars` isn't great, but fixing
that should be part of a bigger refactoring of name mangling we still
need to do: scala#5936.
@smarter
Copy link
Member

smarter commented Jul 21, 2019

Fixed by #6903, meanwhile you can work around the problem by giving a name to your given.

odersky added a commit that referenced this issue Jul 22, 2019
Fix #6902: Avoid illegal characters for generated given names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants