File tree 4 files changed +48
-0
lines changed
compiler/src/dotty/tools/dotc
4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -1006,6 +1006,7 @@ class Definitions {
1006
1006
@ tu lazy val ProvisionalSuperClassAnnot : ClassSymbol = requiredClass(" scala.annotation.internal.ProvisionalSuperClass" )
1007
1007
@ tu lazy val DeprecatedAnnot : ClassSymbol = requiredClass(" scala.deprecated" )
1008
1008
@ tu lazy val DeprecatedOverridingAnnot : ClassSymbol = requiredClass(" scala.deprecatedOverriding" )
1009
+ @ tu lazy val deprecatedInheritance : ClassSymbol = requiredClass(" scala.deprecatedInheritance" )
1009
1010
@ tu lazy val ImplicitAmbiguousAnnot : ClassSymbol = requiredClass(" scala.annotation.implicitAmbiguous" )
1010
1011
@ tu lazy val ImplicitNotFoundAnnot : ClassSymbol = requiredClass(" scala.annotation.implicitNotFound" )
1011
1012
@ 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 {
114
114
}
115
115
end checkSelfAgainstParents
116
116
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
+
117
127
/** Check that self type of this class conforms to self types of parents
118
128
* and required classes. Also check that only `enum` constructs extend
119
129
* `java.lang.Enum` and no user-written class extends ContextFunctionN.
@@ -123,6 +133,8 @@ object RefChecks {
123
133
val psyms = cls.asClass.parentSyms
124
134
checkSelfAgainstParents(cls.asClass, psyms)
125
135
136
+ warnDeprecatedInheritance(cls.asClass, parentTrees)
137
+
126
138
def isClassExtendingJavaEnum =
127
139
! cls.isOneOf(Enum | Trait ) && psyms.contains(defn.JavaEnumClass )
128
140
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