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

I can call $asInstanceOf #11843

Open
hrhino opened this issue Jan 1, 2020 · 1 comment · May be fixed by scala/scala#8639
Open

I can call $asInstanceOf #11843

hrhino opened this issue Jan 1, 2020 · 1 comment · May be fixed by scala/scala#8639

Comments

@hrhino
Copy link
Member

@hrhino hrhino commented Jan 1, 2020

and with it, I can cause bad things to happen:

scala> "".$asInstanceOf[Symbol]
java.lang.ClassCastException: java.lang.String cannot be cast to scala.Symbol
  ... 28 elided

which, wait, I could do that already. But I can also do this:

scala> "".$asInstanceOf[Int]
ReplGlobal.abort: Erasure should have added an unboxing operation to prevent this cast. Tree: "".$asInstanceOf[Int]()
error:
  Erasure should have added an unboxing operation to prevent this cast. Tree: "".$asInstanceOf[Int]()
     while compiling: <console>
        during phase: jvm
     library version: version 2.12.11-20191213-034532-9761528
    compiler version: version 2.12.11-20191213-034532-9761528
  reconstructed args: -deprecation -feature -usejavacp

  last tree to typer: This(object iw)
       tree position: line 11 of <console>
            tree tpe: type
              symbol: object iw in package $line10
   symbol definition: class iw extends Object (a ModuleClassSymbol)
      symbol package: $line10
       symbol owners: object iw
           call site: constructor $iw in package $line10

== Source file context for tree position ==

     8 object $iw {
     9 object $iw {
    10
    11 val res1 =
    12 "".$asInstanceOf[Int]
    13
    14 }
@hrhino hrhino added this to the Backlog milestone Jan 1, 2020
@som-snytt som-snytt linked a pull request that will close this issue Jan 15, 2020
@som-snytt

This comment has been minimized.

Copy link

@som-snytt som-snytt commented Jan 15, 2020

scala.ScalaReflectionException: AnyRef.$asInstanceOf is an internal method, it cannot be invoked with mirrors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.