From 40aafbdf1a9a52c1236f07e06d48fb24b5fa2169 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 7 Aug 2010 21:06:46 +0000 Subject: Modified r22702 to avoid tarring overloads with... Modified r22702 to avoid tarring overloads with the same brush. No review. --- .../scala/tools/nsc/typechecker/SuperAccessors.scala | 18 ++++++++++++------ test/files/neg/bug3736.scala | 13 +++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index 16c6203474..7662e0a670 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -25,7 +25,10 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT // inherits abstract value `global' and class `Phase' from Transform import global._ - import definitions.{ IntClass, UnitClass, ByNameParamClass, Any_asInstanceOf, Object_## } + import definitions.{ + IntClass, UnitClass, ByNameParamClass, Any_asInstanceOf, + Any_isInstanceOf, Object_isInstanceOf, Object_##, Object_==, Object_!= + } /** the following two members override abstract members in Transform */ val phaseName: String = "superaccessors" @@ -124,10 +127,13 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT // Disallow some super.XX calls targeting Any methods which would // otherwise lead to either a compiler crash or runtime failure. - private def isDisallowed(name: Name) = name match { - case nme.HASHHASH | nme.EQ | nme.NE | nme.isInstanceOf_ => true - case _ => false - } + private def isDisallowed(sym: Symbol) = ( + (sym == Any_isInstanceOf) || + (sym == Object_isInstanceOf) || + (sym == Object_==) || + (sym == Object_!=) || + (sym == Object_##) + ) override def transform(tree: Tree): Tree = { val sym = tree.symbol @@ -205,7 +211,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT unit.error(tree.pos, "super may be not be used on "+ (if (sym.hasFlag(ACCESSOR)) sym.accessed else sym)) } - else if (isDisallowed(name)) { + else if (isDisallowed(sym)) { unit.error(tree.pos, "super not allowed here: use this." + name.decode + " instead") } transformSuperSelect(tree) diff --git a/test/files/neg/bug3736.scala b/test/files/neg/bug3736.scala index 8e63021f69..cf0920912a 100644 --- a/test/files/neg/bug3736.scala +++ b/test/files/neg/bug3736.scala @@ -8,6 +8,19 @@ object Test { def f6 = super.## } + // Ill-advised overloads to be sure... + class B { + def ##(x: String) = true + def ==(x1: String, xs: List[_]) = true + def !=(x1: String, xs: List[_]) = true + } + + class C extends B { + override def ##(x: String) = super.##(x) + override def ==(x1: String, xs: List[_]) = super.==(x1, xs) + override def !=(x1: String, xs: List[_]) = super.!=(x1, xs) + } + def main(args: Array[String]): Unit = { val x = new A x.f1 -- cgit v1.2.3