From c4bc5bc26afd0356d38374955462dd8aea8782bd Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 21 Aug 2006 17:35:21 +0000 Subject: --- .../scala/tools/nsc/typechecker/RefChecks.scala | 13 ++++++++++++ .../scala/tools/nsc/typechecker/Typers.scala | 24 +++++++++------------- test/files/neg/bug711.check | 2 +- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 6a9d3b9ab4..e5c82085fb 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -69,6 +69,8 @@ abstract class RefChecks extends InfoTransform { * 1.8.2 M is of type []S, O is of type ()T and S <: T, or * 1.8.3 M is of type ()S, O is of type []T and S <: T, or * 2. Check that only abstract classes have deferred members + * 3. Check that every member with an `override' modifier + * overrides some other member. */ private def checkAllOverrides(clazz: Symbol): unit = { @@ -239,6 +241,17 @@ abstract class RefChecks extends InfoTransform { else "")) } } + + // 3. Check that every defined member with an `override' modifier overrides some other member. + for (val member <- clazz.info.decls.toList) + if ((member hasFlag (OVERRIDE | ABSOVERRIDE)) && + (clazz.info.baseClasses.tail forall { + bc => member.matchingSymbol(bc, clazz.thisType) == NoSymbol + })) { + // for (val bc <- clazz.info.baseClasses.tail) System.out.println("" + bc + " has " + bc.info.decl(member.name) + ":" + bc.info.decl(member.name).tpe);//DEBUG + unit.error(member.pos, member.toString() + " overrides nothing"); + member resetFlag OVERRIDE + } } // Basetype Checking -------------------------------------------------------- diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index c9b75eaf73..c01cbdb689 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -984,8 +984,15 @@ trait Typers requires Analyzer { def typedRefinement(stats: List[Tree]): List[Tree] = { namer.enterSyms(stats) - for (val stat <- stats) stat.symbol setFlag OVERRIDE - typedStats(stats, NoSymbol) + val stats1 = typedStats(stats, NoSymbol) + for (val stat <- stats1; stat.isDef) { + val member = stat.symbol + member setFlag OVERRIDE + if (context.owner.info.baseClasses.tail forall + (bc => member.matchingSymbol(bc, context.owner.thisType) == NoSymbol)) + error(member.pos, member.toString+" does not refine a member of its base type") + } + stats1 } def typedStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = { @@ -1002,18 +1009,7 @@ trait Typers requires Analyzer { case _ => val localTyper = if (inBlock || (stat.isDef && !stat.isInstanceOf[LabelDef])) this else newTyper(context.make(stat, exprOwner)) - val stat1 = localTyper.typed(stat) - val member = stat1.symbol - // Check that every defined member with an `override' modifier - // overrides some other member - if (stat1.isDef && - (member hasFlag(OVERRIDE | ABSOVERRIDE)) && - (context.owner.info.baseClasses.tail forall - (bc => member.matchingSymbol(bc, context.owner.thisType) == NoSymbol))) { - error(member.pos, member.toString+" overrides nothing") - member resetFlag OVERRIDE - } - stat1 + localTyper.typed(stat) } } val scope = if (inBlock) context.scope else context.owner.info.decls; diff --git a/test/files/neg/bug711.check b/test/files/neg/bug711.check index 401677af6b..3511f0c3ea 100644 --- a/test/files/neg/bug711.check +++ b/test/files/neg/bug711.check @@ -1,4 +1,4 @@ -bug711.scala:11 error: method sayHey overrides nothing +bug711.scala:11 error: method sayHey does not refine a member of its base type def sayHey: Unit ^ one error found -- cgit v1.2.3