File tree Expand file tree Collapse file tree 4 files changed +48
-0
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -1006,6 +1006,7 @@ class Definitions {
10061006 @ tu lazy val ProvisionalSuperClassAnnot : ClassSymbol = requiredClass(" scala.annotation.internal.ProvisionalSuperClass" )
10071007 @ tu lazy val DeprecatedAnnot : ClassSymbol = requiredClass(" scala.deprecated" )
10081008 @ tu lazy val DeprecatedOverridingAnnot : ClassSymbol = requiredClass(" scala.deprecatedOverriding" )
1009+ @ tu lazy val deprecatedInheritance : ClassSymbol = requiredClass(" scala.deprecatedInheritance" )
10091010 @ tu lazy val ImplicitAmbiguousAnnot : ClassSymbol = requiredClass(" scala.annotation.implicitAmbiguous" )
10101011 @ tu lazy val ImplicitNotFoundAnnot : ClassSymbol = requiredClass(" scala.annotation.implicitNotFound" )
10111012 @ tu lazy val InlineParamAnnot : ClassSymbol = requiredClass(" scala.annotation.internal.InlineParam" )
Original file line number Diff line number Diff line change @@ -114,6 +114,16 @@ object RefChecks {
114114 }
115115 end checkSelfAgainstParents
116116
117+ /** warn if `@deprecatedInheritance` is present */
118+ def warnDeprecatedInheritance (cls : ClassSymbol , parentTrees : List [Tree ])(using Context ): Unit =
119+ val psyms = cls.parentSyms
120+ for (psym, pos) <- psyms.zip(parentTrees.map(_.srcPos))
121+ annot <- psym.getAnnotation(defn.deprecatedInheritance)
122+ do
123+ val msg = annot.argumentConstantString(0 ).getOrElse(" " )
124+ val since = annot.argumentConstantString(1 ).getOrElse(" " )
125+ report.deprecationWarning(em " inheritance from $psym is deprecated (since: $since): $msg" , pos)
126+
117127 /** Check that self type of this class conforms to self types of parents
118128 * and required classes. Also check that only `enum` constructs extend
119129 * `java.lang.Enum` and no user-written class extends ContextFunctionN.
@@ -123,6 +133,8 @@ object RefChecks {
123133 val psyms = cls.asClass.parentSyms
124134 checkSelfAgainstParents(cls.asClass, psyms)
125135
136+ warnDeprecatedInheritance(cls.asClass, parentTrees)
137+
126138 def isClassExtendingJavaEnum =
127139 ! cls.isOneOf(Enum | Trait ) && psyms.contains(defn.JavaEnumClass )
128140
Original file line number Diff line number Diff line change 1+ -- Deprecation Warning: tests/warn/i19002.scala:5:20 -------------------------------------------------------------------
2+ 5 |class TBar1 extends TFoo // warn
3+ | ^^^^
4+ | inheritance from trait TFoo is deprecated (since: FooLib 12.0): this class will be made final
5+ -- Deprecation Warning: tests/warn/i19002.scala:6:20 -------------------------------------------------------------------
6+ 6 |trait TBar2 extends TFoo // warn
7+ | ^^^^
8+ | inheritance from trait TFoo is deprecated (since: FooLib 12.0): this class will be made final
9+ -- Deprecation Warning: tests/warn/i19002.scala:10:20 ------------------------------------------------------------------
10+ 10 |class CBar1 extends CFoo // warn
11+ | ^^^^
12+ | inheritance from class CFoo is deprecated (since: FooLib 11.0): this class will be made final
13+ -- Deprecation Warning: tests/warn/i19002.scala:14:20 ------------------------------------------------------------------
14+ 14 |class ABar1 extends AFoo // warn
15+ | ^^^^
16+ | inheritance from class AFoo is deprecated (since: FooLib 10.0): this class will be made final
17+ -- Deprecation Warning: tests/warn/i19002.scala:15:20 ------------------------------------------------------------------
18+ 15 |trait ABar2 extends AFoo // warn
19+ | ^^^^
20+ | inheritance from class AFoo is deprecated (since: FooLib 10.0): this class will be made final
Original file line number Diff line number Diff line change 1+ //> using options -deprecation
2+
3+ @ deprecatedInheritance(" this class will be made final" , " FooLib 12.0" )
4+ trait TFoo
5+ class TBar1 extends TFoo // warn
6+ trait TBar2 extends TFoo // warn
7+
8+ @ deprecatedInheritance(" this class will be made final" , " FooLib 11.0" )
9+ class CFoo
10+ class CBar1 extends CFoo // warn
11+
12+ @ deprecatedInheritance(" this class will be made final" , " FooLib 10.0" )
13+ abstract class AFoo
14+ class ABar1 extends AFoo // warn
15+ trait ABar2 extends AFoo // warn
You can’t perform that action at this time.
0 commit comments