From 54d11fe5451a9f26207ce283f2df1114c89384dd Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Fri, 29 Mar 2013 19:05:13 +0100 Subject: SI-7312 @deprecatedInheritance now ignores same-file subclasses This allows us to deprecate external inheritances as a prelude to sealing a class, without enduring the warnings ourselved in interlude. --- .../scala/tools/nsc/typechecker/Typers.scala | 6 ++++-- src/library/scala/deprecatedInheritance.scala | 3 ++- test/files/neg/t6162-inheritance.check | 10 +++++----- test/files/neg/t6162-inheritance.scala | 19 ------------------- test/files/neg/t6162-inheritance/defn.scala | 10 ++++++++++ test/files/neg/t6162-inheritance/usage.scala | 10 ++++++++++ test/files/pos/t6162-inheritance.flags | 1 + test/files/pos/t6162-inheritance.scala | 22 ++++++++++++++++++++++ 8 files changed, 54 insertions(+), 27 deletions(-) delete mode 100644 test/files/neg/t6162-inheritance.scala create mode 100644 test/files/neg/t6162-inheritance/defn.scala create mode 100644 test/files/neg/t6162-inheritance/usage.scala create mode 100644 test/files/pos/t6162-inheritance.flags create mode 100644 test/files/pos/t6162-inheritance.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 5e31395215..6719411700 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1738,14 +1738,16 @@ trait Typers extends Adaptations with Tags { if (psym.isFinal) pending += ParentFinalInheritanceError(parent, psym) - if (psym.hasDeprecatedInheritanceAnnotation) { + val sameSourceFile = context.unit.source.file == psym.sourceFile + + if (psym.hasDeprecatedInheritanceAnnotation && !sameSourceFile) { val suffix = psym.deprecatedInheritanceMessage map (": " + _) getOrElse "" val msg = s"inheritance from ${psym.fullLocationString} is deprecated$suffix" unit.deprecationWarning(parent.pos, msg) } if (psym.isSealed && !phase.erasedTypes) - if (context.unit.source.file == psym.sourceFile) + if (sameSourceFile) psym addChild context.owner else pending += ParentSealedInheritanceError(parent, psym) diff --git a/src/library/scala/deprecatedInheritance.scala b/src/library/scala/deprecatedInheritance.scala index 70065560b1..7d20219d4d 100644 --- a/src/library/scala/deprecatedInheritance.scala +++ b/src/library/scala/deprecatedInheritance.scala @@ -11,7 +11,8 @@ package scala /** An annotation that designates that inheriting from a class is deprecated. * * This is usually done to warn about a non-final class being made final in a future version. - * Sub-classing such a class then generates a warning. + * Sub-classing such a class then generates a warning. No warnings are generated if the + * subclass is in the same compilation unit. * * @param message the message to print during compilation if the class was sub-classed * @param since a string identifying the first version in which inheritance was deprecated diff --git a/test/files/neg/t6162-inheritance.check b/test/files/neg/t6162-inheritance.check index e98fa79eb7..13c78030d9 100644 --- a/test/files/neg/t6162-inheritance.check +++ b/test/files/neg/t6162-inheritance.check @@ -1,16 +1,16 @@ -t6162-inheritance.scala:6: warning: inheritance from class Foo in package t6126 is deprecated: `Foo` will be made final in a future version. +usage.scala:3: warning: inheritance from class Foo in package t6126 is deprecated: `Foo` will be made final in a future version. class SubFoo extends Foo ^ -t6162-inheritance.scala:11: warning: inheritance from trait T in package t6126 is deprecated +usage.scala:5: warning: inheritance from trait T in package t6126 is deprecated object SubT extends T ^ -t6162-inheritance.scala:17: warning: inheritance from trait S in package t6126 is deprecated +usage.scala:8: warning: inheritance from trait S in package t6126 is deprecated new S { ^ -t6162-inheritance.scala:6: warning: inheritance from class Foo in package t6126 is deprecated: `Foo` will be made final in a future version. +usage.scala:3: warning: inheritance from class Foo in package t6126 is deprecated: `Foo` will be made final in a future version. class SubFoo extends Foo ^ -t6162-inheritance.scala:11: warning: inheritance from trait T in package t6126 is deprecated +usage.scala:5: warning: inheritance from trait T in package t6126 is deprecated object SubT extends T ^ error: No warnings can be incurred under -Xfatal-warnings. diff --git a/test/files/neg/t6162-inheritance.scala b/test/files/neg/t6162-inheritance.scala deleted file mode 100644 index 7b47b9285a..0000000000 --- a/test/files/neg/t6162-inheritance.scala +++ /dev/null @@ -1,19 +0,0 @@ -package scala.t6126 - -@deprecatedInheritance("`Foo` will be made final in a future version.", "2.10.0") -class Foo - -class SubFoo extends Foo - -@deprecatedInheritance() -trait T - -object SubT extends T - -@deprecatedInheritance() -trait S - -object O { - new S { - } -} diff --git a/test/files/neg/t6162-inheritance/defn.scala b/test/files/neg/t6162-inheritance/defn.scala new file mode 100644 index 0000000000..bb582d27b0 --- /dev/null +++ b/test/files/neg/t6162-inheritance/defn.scala @@ -0,0 +1,10 @@ +package scala.t6126 + +@deprecatedInheritance("`Foo` will be made final in a future version.", "2.10.0") +class Foo + +@deprecatedInheritance() +trait T + +@deprecatedInheritance() +trait S diff --git a/test/files/neg/t6162-inheritance/usage.scala b/test/files/neg/t6162-inheritance/usage.scala new file mode 100644 index 0000000000..097e4f5903 --- /dev/null +++ b/test/files/neg/t6162-inheritance/usage.scala @@ -0,0 +1,10 @@ +package scala.t6126 + +class SubFoo extends Foo + +object SubT extends T + +object O { + new S { + } +} diff --git a/test/files/pos/t6162-inheritance.flags b/test/files/pos/t6162-inheritance.flags new file mode 100644 index 0000000000..c6bfaf1f64 --- /dev/null +++ b/test/files/pos/t6162-inheritance.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings diff --git a/test/files/pos/t6162-inheritance.scala b/test/files/pos/t6162-inheritance.scala new file mode 100644 index 0000000000..fca751edab --- /dev/null +++ b/test/files/pos/t6162-inheritance.scala @@ -0,0 +1,22 @@ +package scala.t6126 + +// Don't warn about inheritance in the same file. +// We might use that as a prelude to sealing a class. + +@deprecatedInheritance("`Foo` will be made final in a future version.", "2.10.0") +class Foo + +class SubFoo extends Foo + +@deprecatedInheritance() +trait T + +object SubT extends T + +@deprecatedInheritance() +trait S + +object O { + new S { + } +} -- cgit v1.2.3 From 660c8fd4c89c4f7121d131138c5f9fceaefa4992 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sat, 30 Mar 2013 10:02:34 +0100 Subject: SI-7315 Test @deprecatedInheritance / @specialized interplay Don't warn about the specialized subclass. Fixed in the previous commit for a similar issue SI-7312. --- test/files/pos/t7315.flags | 1 + test/files/pos/t7315.scala | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 test/files/pos/t7315.flags create mode 100644 test/files/pos/t7315.scala diff --git a/test/files/pos/t7315.flags b/test/files/pos/t7315.flags new file mode 100644 index 0000000000..d1b831ea87 --- /dev/null +++ b/test/files/pos/t7315.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings \ No newline at end of file diff --git a/test/files/pos/t7315.scala b/test/files/pos/t7315.scala new file mode 100644 index 0000000000..0abcea2451 --- /dev/null +++ b/test/files/pos/t7315.scala @@ -0,0 +1,4 @@ +package scala.pack + +@deprecatedInheritance +class C[@specialized A] \ No newline at end of file -- cgit v1.2.3