Skip to content

Commit f85c62e

Browse files
committed
Fix erasure of the qualifier of ##
1 parent b9d4089 commit f85c62e

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/compiler/scala/tools/nsc/transform/Erasure.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,20 +1060,21 @@ abstract class Erasure extends InfoTransform
10601060
}
10611061
else if (args.isEmpty && interceptedMethods(fn.symbol)) {
10621062
if (poundPoundMethods.contains(fn.symbol)) {
1063+
val qual1 = preErase(qual)
10631064
// This is unattractive, but without it we crash here on ().## because after
10641065
// erasure the ScalaRunTime.hash overload goes from Unit => Int to BoxedUnit => Int.
10651066
// This must be because some earlier transformation is being skipped on ##, but so
10661067
// far I don't know what. For null we now define null.## == 0.
10671068
def staticsCall(methodName: TermName): Tree = {
1068-
val newTree = gen.mkMethodCall(RuntimeStaticsModule, methodName, qual :: Nil)
1069+
val newTree = gen.mkMethodCall(RuntimeStaticsModule, methodName, qual1 :: Nil)
10691070
global.typer.typed(newTree)
10701071
}
10711072

1072-
qual.tpe.typeSymbol match {
1073-
case UnitClass | NullClass => LIT(0)
1074-
case IntClass => qual
1075-
case s @ (ShortClass | ByteClass | CharClass) => numericConversion(qual, s)
1076-
case BooleanClass => If(qual, LIT(true.##), LIT(false.##))
1073+
qual1.tpe.typeSymbol match {
1074+
case UnitClass | NullClass => BLOCK(qual1, LIT(0))
1075+
case IntClass => qual1
1076+
case s @ (ShortClass | ByteClass | CharClass) => numericConversion(qual1, s)
1077+
case BooleanClass => If(qual1, LIT(true.##), LIT(false.##))
10771078
case LongClass => staticsCall(nme.longHash)
10781079
case FloatClass => staticsCall(nme.floatHash)
10791080
case DoubleClass => staticsCall(nme.doubleHash)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
assert(1.##.## == 1) // was java.lang.NoSuchMethodError: java.lang.Object.$hash$hash()I
4+
}
5+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object Ex extends Exception
2+
object Test {
3+
def ex: Any = throw Ex
4+
def main(args: Array[String]): Unit = {
5+
try {
6+
{ ex; () }.##
7+
sys.error("no exception was thrown")
8+
} catch {
9+
case `Ex` =>
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)