summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala31
-rw-r--r--test/files/pos/hashhash-overloads.scala6
2 files changed, 22 insertions, 15 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index 250101a636..7bba5fa227 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -400,21 +400,12 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer with ast.
}
val deconstMap = new TypeMap {
- def apply(tp: Type): Type = tp match {
- case PolyType(_, _) => mapOver(tp)
- case MethodType(_, _) => mapOver(tp) // nullarymethod was eliminated during uncurry
- case _ => tp.deconst
- }
- }
-
- /** The symbol which is called by a bridge;
- * @pre phase > erasure
- */
- def bridgedSym(bridge: Symbol) =
- bridge.owner.info.nonPrivateDecl(bridge.name) suchThat { sym =>
- !sym.isBridge && matchesType(sym.tpe, bridge.tpe, true) &&
- (sym.tpe.resultType <:< bridge.tpe.resultType)
+ def apply(tp: Type): Type = tp match {
+ case PolyType(_, _) => mapOver(tp)
+ case MethodType(_, _) => mapOver(tp) // nullarymethod was eliminated during uncurry
+ case _ => tp.deconst
}
+ }
// -------- erasure on trees ------------------------------------------
@@ -970,7 +961,17 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer with ast.
args)
case Apply(fn @ Select(qual, _), Nil) if (fn.symbol == Any_## || fn.symbol == Object_##) =>
- Apply(gen.mkAttributedRef(scalaRuntimeHash), List(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. We also crash on null.## but unless we want to implement
+ // my good idea that null.## works (like null == "abc" works) we have to NPE.
+ val arg = qual.tpe.typeSymbol match {
+ case UnitClass => BLOCK(qual, REF(BoxedUnit_UNIT)) // ({ expr; UNIT }).##
+ case NullClass => Typed(qual, TypeTree(ObjectClass.tpe)) // (null: Object).##
+ case _ => qual
+ }
+ Apply(gen.mkAttributedRef(scalaRuntimeHash), List(arg))
case Apply(fn, args) =>
if (fn.symbol == Any_asInstanceOf)
diff --git a/test/files/pos/hashhash-overloads.scala b/test/files/pos/hashhash-overloads.scala
new file mode 100644
index 0000000000..40519bae06
--- /dev/null
+++ b/test/files/pos/hashhash-overloads.scala
@@ -0,0 +1,6 @@
+object Test {
+ def f = ().##
+ def g = 5f.##
+ def h = ({ 5 ; println("abc") }).##
+ def f2 = null.##
+}