Skip to content

Commit

Permalink
Fix erasure of the qualifier of ##
Browse files Browse the repository at this point in the history
  • Loading branch information
retronym committed Jan 24, 2017
1 parent b9d4089 commit f85c62e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/compiler/scala/tools/nsc/transform/Erasure.scala
Expand Up @@ -1060,20 +1060,21 @@ abstract class Erasure extends InfoTransform
}
else if (args.isEmpty && interceptedMethods(fn.symbol)) {
if (poundPoundMethods.contains(fn.symbol)) {
val qual1 = preErase(qual)
// This is unattractive, but without it we crash here on ().## because after
// erasure the ScalaRunTime.hash overload goes from Unit => Int to BoxedUnit => Int.
// This must be because some earlier transformation is being skipped on ##, but so
// far I don't know what. For null we now define null.## == 0.
def staticsCall(methodName: TermName): Tree = {
val newTree = gen.mkMethodCall(RuntimeStaticsModule, methodName, qual :: Nil)
val newTree = gen.mkMethodCall(RuntimeStaticsModule, methodName, qual1 :: Nil)
global.typer.typed(newTree)
}

qual.tpe.typeSymbol match {
case UnitClass | NullClass => LIT(0)
case IntClass => qual
case s @ (ShortClass | ByteClass | CharClass) => numericConversion(qual, s)
case BooleanClass => If(qual, LIT(true.##), LIT(false.##))
qual1.tpe.typeSymbol match {
case UnitClass | NullClass => BLOCK(qual1, LIT(0))
case IntClass => qual1
case s @ (ShortClass | ByteClass | CharClass) => numericConversion(qual1, s)
case BooleanClass => If(qual1, LIT(true.##), LIT(false.##))
case LongClass => staticsCall(nme.longHash)
case FloatClass => staticsCall(nme.floatHash)
case DoubleClass => staticsCall(nme.doubleHash)
Expand Down
5 changes: 5 additions & 0 deletions test/files/run/hash-hash-hash-hash.scala
@@ -0,0 +1,5 @@
object Test {
def main(args: Array[String]): Unit = {
assert(1.##.## == 1) // was java.lang.NoSuchMethodError: java.lang.Object.$hash$hash()I
}
}
12 changes: 12 additions & 0 deletions test/files/run/unit-block-hash-hash.scala
@@ -0,0 +1,12 @@
object Ex extends Exception
object Test {
def ex: Any = throw Ex
def main(args: Array[String]): Unit = {
try {
{ ex; () }.##
sys.error("no exception was thrown")
} catch {
case `Ex` =>
}
}
}

0 comments on commit f85c62e

Please sign in to comment.