diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Symbols.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 27 |
2 files changed, 25 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index c5892b79fb..dab6870aeb 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -209,6 +209,8 @@ trait Symbols requires SymbolTable { final def isRootPackage = isPackage && name == nme.ROOTPKG final def isEmptyPackage = isPackage && name == nme.EMPTY_PACKAGE_NAME final def isEmptyPackageClass = isPackageClass && name == nme.EMPTY_PACKAGE_NAME.toTypeName + def isDeprecated = + attributes exists (attr => attr._1.symbol == DeprecatedAttr) /** Does this symbol denote a wrapper object of the interpreter or its class? */ final def isInterpreterWrapper = diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index b964c73297..89bab81fd8 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -424,15 +424,14 @@ trait Typers requires Analyzer { * </ol> */ private def stabilize(tree: Tree, pre: Type, mode: int, pt: Type): Tree = { - def isDeprecated(sym: Symbol) = - sym.attributes exists (attr => attr._1.symbol == DeprecatedAttr) + def isDeprecated(sym: Symbol) = sym.isDeprecated if (tree.symbol.hasFlag(OVERLOADED) && (mode & FUNmode) == 0) inferExprAlternative(tree, pt) val sym = tree.symbol if (!phase.erasedTypes && isDeprecated(sym) && !context.owner.ownerChain.exists(isDeprecated)) { unit.deprecationWarning(tree.pos, - sym+sym.locationString+" is deprecated;\n see API documentation for alternatives") + sym+sym.locationString+" is deprecated") } if (tree.tpe.isError) tree else if ((mode & (PATTERNmode | FUNmode)) == PATTERNmode && tree.isTerm) { // (1) @@ -758,7 +757,7 @@ trait Typers requires Analyzer { /** <p>Check that</p> * <ul> * <li>all parents are class types,</li> - * <li>first parent cluss is not a mixin; following classes are mixins,</li> + * <li>first parent class is not a mixin; following classes are mixins,</li> * <li>final classes are not inherited,</li> * <li> * sealed classes are only inherited by classes which are @@ -941,6 +940,7 @@ trait Typers requires Analyzer { } else { newTyper(context.make(vdef, sym)).transformedOrTyped(vdef.rhs, tpt1.tpe) } + checkDeprecatedOvers(vdef) copy.ValDef(vdef, vdef.mods, vdef.name, tpt1, rhs1) setType NoType } @@ -1007,6 +1007,24 @@ trait Typers requires Analyzer { } } + /** Check that a deprecated val or def does not override a + * concrete, non-deprecated method. If it does, then + * deprecation is meaningless. + */ + def checkDeprecatedOvers(tree: Tree): Unit = { + if(!phase.erasedTypes ) return () + val symbol = tree.symbol + if(!symbol.isDeprecated) return () + val concrOvers = + symbol.allOverriddenSymbols.filter(sym => + !sym.isDeprecated && !(sym hasFlag DEFERRED)) + if(!concrOvers.isEmpty) + unit.deprecationWarning( + tree.pos, + symbol.toString + " overrides concrete, non-deprecated symbol(s):" + + concrOvers.map(.fullNameString).mkString(" ", ", ", "")) + } + /** * @param ddef ... * @return ... @@ -1068,6 +1086,7 @@ trait Typers requires Analyzer { computeParamAliases(meth.owner, vparamss1, result) result } else transformedOrTyped(ddef.rhs, tpt1.tpe) + checkDeprecatedOvers(ddef) copy.DefDef(ddef, ddef.mods, ddef.name, tparams1, vparamss1, tpt1, rhs1) setType NoType } |