Skip to content

I can call $asInstanceOf$ #8869

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
som-snytt opened this issue May 4, 2020 · 2 comments
Closed

I can call $asInstanceOf$ #8869

som-snytt opened this issue May 4, 2020 · 2 comments

Comments

@som-snytt
Copy link
Contributor

Minimized code

Starting dotty REPL...
Dotty compiler version 0.25.0-bin-SNAPSHOT-git-66f335c -- Copyright 2002-2020, LAMP/EPFL
scala> "".$asInstanceOf$[Int]                                                                                          
Caught: dotty.tools.dotc.core.CyclicReference:  while parsing annotations in /modules/java.base/java/lang/annotation/ElementType.class
java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Integer (java.lang.String and java.lang.Integer are in module java.base of loader 'bootstrap')
	at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:99)
	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 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	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:291)
	at scala.collection.immutable.List.map(List.scala:246)
	at scala.collection.immutable.List.map(List.scala:79)
	at dotty.tools.repl.ReplDriver.displayMembers$6(ReplDriver.scala:291)
	at dotty.tools.repl.ReplDriver.displayDefinitions$$anonfun$2(ReplDriver.scala:317)
	at scala.Option.map(Option.scala:242)
	at dotty.tools.repl.ReplDriver.displayDefinitions(ReplDriver.scala:317)
	at dotty.tools.repl.ReplDriver.compile$$anonfun$2(ReplDriver.scala:245)
	at scala.util.Either.fold(Either.scala:189)
	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:247)
	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 dotty.tools.repl.Main$.main(Main.scala:6)
	at dotty.tools.repl.Main.main(Main.scala)

Output

Exception in thread "main" java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Integer (java.lang.String and java.lang.Integer are in module java.base of loader 'bootstrap')
	at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:99)
	at asinstanceof$package$.badinstanceof(asinstanceof.scala:2)
	at badinstanceof.main(asinstanceof.scala:2)

Expectation

Forward port of scala/bug#11843

@odersky
Copy link
Contributor

odersky commented Jun 8, 2020

Names with $ in them are reserved for the compiler's use, and the effects of calling them anyway are undefined. So, don't call them.

@odersky odersky closed this as completed Jun 8, 2020
@nicolasstucki
Copy link
Contributor

Maybe we should emit a warning when a name with a is parsed $.

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.

3 participants