Skip to content

I can call $asInstanceOf #11843

@hrhino

Description

@hrhino

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 }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions