diff options
author | Simon Ochsenreither <simon@ochsenreither.de> | 2012-07-31 01:02:07 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2012-09-10 22:57:21 +0200 |
commit | e3b0c7abbf637dacce7bcd7b69d5655820e8e714 (patch) | |
tree | 392819cf24113b893c1622b5ecc80605bd34b3d6 /src/compiler | |
parent | adf2d3632b07eef4fc2303aef994e66584a73f49 (diff) | |
download | scala-e3b0c7abbf637dacce7bcd7b69d5655820e8e714.tar.gz scala-e3b0c7abbf637dacce7bcd7b69d5655820e8e714.tar.bz2 scala-e3b0c7abbf637dacce7bcd7b69d5655820e8e714.zip |
SI-6162 Adds @deprecatedInheritance/@deprecatedOverriding
These annotations are meant to warn from inheriting a class or
from overriding a member, due to the reasons given in `msg`.
The naming and placement of the methods is in line with
@deprecated and @deprecatedName.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 11 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 9 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 166bb2d18c..919250c562 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -430,6 +430,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R overrideError("cannot override a macro") } else { checkOverrideTypes() + checkOverrideDeprecated() if (settings.warnNullaryOverride.value) { if (other.paramss.isEmpty && !member.paramss.isEmpty) { unit.warning(member.pos, "non-nullary method overrides nullary method") @@ -508,6 +509,16 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R } } } + + def checkOverrideDeprecated() { + if (other.hasDeprecatedOverridingAnnotation) { + val msg = + member.toString + member.locationString + " overrides " + other.toString + other.locationString + + ", but overriding this member is deprecated" + + other.deprecatedOverridingMessage.map(": " + _).getOrElse(".") + unit.deprecationWarning(member.pos, msg) + } + } } val opc = new overridingPairs.Cursor(clazz) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 9cf5d42e00..df97e451d1 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1577,6 +1577,15 @@ trait Typers extends Modes with Adaptations with Tags { if (psym.isFinal) pending += ParentFinalInheritanceError(parent, psym) + if (psym.hasDeprecatedInheritanceAnnotation) { + val sym = selfType.typeSymbol + val msg = + sym.toString + sym.locationString + " inherits from " + psym.toString + psym.locationString + + ", but inheriting from that class is deprecated" + + psym.deprecatedInheritanceMessage.map(": " + _).getOrElse(".") + unit.deprecationWarning(sym.pos, msg) + } + if (psym.isSealed && !phase.erasedTypes) if (context.unit.source.file == psym.sourceFile) psym addChild context.owner |