Skip to content

Commit c96a977

Browse files
authored
Merge pull request scala#5658 from retronym/topic/hashhash
Fix erasure of the qualifier of ##
2 parents 76bfb9e + f85c62e commit c96a977

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
@@ -1064,20 +1064,21 @@ abstract class Erasure extends InfoTransform
10641064
}
10651065
else if (args.isEmpty && interceptedMethods(fn.symbol)) {
10661066
if (poundPoundMethods.contains(fn.symbol)) {
1067+
val qual1 = preErase(qual)
10671068
// This is unattractive, but without it we crash here on ().## because after
10681069
// erasure the ScalaRunTime.hash overload goes from Unit => Int to BoxedUnit => Int.
10691070
// This must be because some earlier transformation is being skipped on ##, but so
10701071
// far I don't know what. For null we now define null.## == 0.
10711072
def staticsCall(methodName: TermName): Tree = {
1072-
val newTree = gen.mkMethodCall(RuntimeStaticsModule, methodName, qual :: Nil)
1073+
val newTree = gen.mkMethodCall(RuntimeStaticsModule, methodName, qual1 :: Nil)
10731074
global.typer.typed(newTree)
10741075
}
10751076

1076-
qual.tpe.typeSymbol match {
1077-
case UnitClass | NullClass => LIT(0)
1078-
case IntClass => qual
1079-
case s @ (ShortClass | ByteClass | CharClass) => numericConversion(qual, s)
1080-
case BooleanClass => If(qual, LIT(true.##), LIT(false.##))
1077+
qual1.tpe.typeSymbol match {
1078+
case UnitClass | NullClass => BLOCK(qual1, LIT(0))
1079+
case IntClass => qual1
1080+
case s @ (ShortClass | ByteClass | CharClass) => numericConversion(qual1, s)
1081+
case BooleanClass => If(qual1, LIT(true.##), LIT(false.##))
10811082
case LongClass => staticsCall(nme.longHash)
10821083
case FloatClass => staticsCall(nme.floatHash)
10831084
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)