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
getClass on Unit not erased properly #5568
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5568?orig=1 |
@magarciaEPFL said: (the
How does that code find its way till After superaccessors:
After erasure:
|
@magarciaEPFL said (edited on May 4, 2012 4:47:12 PM UTC): case Apply(fn @ Select(qual, _), Nil) if interceptedMethods(fn.symbol) => but then doesn't get into this branch // Rewrite 5.getClass to ScalaRunTime.anyValClass(5)
else if (isPrimitiveValueClass(qual.tpe.typeSymbol))
global.typer.typed(
gen.mkRuntimeCall(
nme.anyValClass,
List(qual, typer.resolveErasureTag(tree.pos, qual.tpe.widen, true)))) because the qualifier's |
@som-snytt said (edited on Oct 4, 2012 6:11:39 AM UTC): The error is: package fracked
object Test {
//def fraction: PartialFunction[Int, Int] = { case d if d != 0 => 42 / d }
def fraction: PartialFunction[Int, Int] = { case d if d != 0 => println(d.getClass); 42 / d }
//def fraction: PartialFunction[Int, Int] = { case d: Int if d != 0 => println(d.getClass); 42 / d } // ok
//def fraction: PartialFunction[Int, Int] = { case d if d != 0 => println("hello"); 42 / d }
def main(args: Array[String]) {
println(fraction(42))
}
} |
@JamesIry said: |
@JamesIry said: } else if (isPrimitiveValueClass(qual.tpe.typeSymbol)) {
// Rewrite 5.getClass to ScalaRunTime.anyValClass(5)
global.typer.typed(gen.mkRuntimeCall(nme.anyValClass, List(qual, typer.resolveClassTag(tree.pos, qual.tpe.widen))))
} If we go into that one (by hacking in a bit of force) the code that gets generated is very strange and brittle
The result is "java.lang.Object" If instead we go into the next branch } else if (fn.symbol == AnyVal_getClass) {
tree setSymbol Object_getClass Then what we get is totally reasonable
And the result is class scala.runtime.BoxedUnit. Which is nice because that's exactly the same answer as when we do [Unit with AnyRef] instad of [AnyRef with Unit]. What we're currently doing, though, is falling all the way to the default branch and that's getting us into trouble } else {
tree
} |
@JamesIry said: |
You shouldn't be able to cast your way to a VerifyError.
The text was updated successfully, but these errors were encountered: