@@ -32,10 +32,16 @@ class CrossVersionChecks extends MiniPhase:
32
32
checkMigration(sym, pos, xMigrationValue)
33
33
end checkUndesiredProperties
34
34
35
- /** If @deprecated is present, and the point of reference is not enclosed
36
- * in either a deprecated member or a scala bridge method, issue a warning.
37
- */
38
- private def checkDeprecated (sym : Symbol , pos : SrcPos )(using Context ): Unit =
35
+ /** Skip warnings for synthetic members of case classes during declaration and
36
+ * scan the chain of outer declaring scopes from the current context
37
+ * a deprecation warning will be skipped if one the following holds
38
+ * for a given declaring scope:
39
+ * - the symbol associated with the scope is also deprecated.
40
+ * - if and only if `sym` is an enum case, the scope is either
41
+ * a module that declares `sym`, or the companion class of the
42
+ * module that declares `sym`.
43
+ */
44
+ def skipWarning (sym : Symbol )(using Context ): Boolean = {
39
45
40
46
/** is the owner an enum or its companion and also the owner of sym */
41
47
def isEnumOwner (owner : Symbol )(using Context ) =
@@ -46,26 +52,22 @@ class CrossVersionChecks extends MiniPhase:
46
52
47
53
def isDeprecatedOrEnum (owner : Symbol )(using Context ) =
48
54
// pre: sym is an enumcase
49
- owner.isDeprecated
50
- || isEnumOwner(owner)
51
-
52
- /** Skip warnings for synthetic members of case classes during declaration and
53
- * scan the chain of outer declaring scopes from the current context
54
- * a deprecation warning will be skipped if one the following holds
55
- * for a given declaring scope:
56
- * - the symbol associated with the scope is also deprecated.
57
- * - if and only if `sym` is an enum case, the scope is either
58
- * a module that declares `sym`, or the companion class of the
59
- * module that declares `sym`.
60
- */
61
- def skipWarning (using Context ): Boolean =
62
- (ctx.owner.is(Synthetic ) && sym.is(CaseClass ))
63
- || ctx.owner.ownersIterator.exists(if sym.isEnumCase then isDeprecatedOrEnum else _.isDeprecated)
55
+ owner.isDeprecated || isEnumOwner(owner)
56
+
57
+ (ctx.owner.is(Synthetic ) && sym.is(CaseClass ))
58
+ || ctx.owner.ownersIterator.exists(if sym.isEnumCase then isDeprecatedOrEnum else _.isDeprecated)
59
+ }
60
+
61
+
62
+ /** If @deprecated is present, and the point of reference is not enclosed
63
+ * in either a deprecated member or a scala bridge method, issue a warning.
64
+ */
65
+ private def checkDeprecated (sym : Symbol , pos : SrcPos )(using Context ): Unit =
64
66
65
67
// Also check for deprecation of the companion class for synthetic methods
66
68
val toCheck = sym :: (if sym.isAllOf(SyntheticMethod ) then sym.owner.companionClass :: Nil else Nil )
67
69
for sym <- toCheck; annot <- sym.getAnnotation(defn.DeprecatedAnnot ) do
68
- if ! skipWarning then
70
+ if ! skipWarning(sym) then
69
71
val msg = annot.argumentConstant(0 ).map(" : " + _.stringValue).getOrElse(" " )
70
72
val since = annot.argumentConstant(1 ).map(" since " + _.stringValue).getOrElse(" " )
71
73
report.deprecationWarning(em " ${sym.showLocated} is deprecated ${since}${msg}" , pos)
@@ -107,6 +109,18 @@ class CrossVersionChecks extends MiniPhase:
107
109
}
108
110
}
109
111
112
+ /** ??? */
113
+ def checkDeprecatedInheritance (parents : List [Tree ])(using Context ): Unit = {
114
+ val cls = ctx.owner.asClass
115
+ for (psym, pos) <- cls.parentSyms.zip(parents.map(_.srcPos))
116
+ annot <- psym.getAnnotation(defn.DeprecatedInheritanceAnnot )
117
+ do
118
+ if ! skipWarning(psym) then
119
+ val msg = annot.argumentConstantString(0 ).map(msg => s " : $msg" ).getOrElse(" " )
120
+ val since = annot.argumentConstantString(1 ).map(version => s " (since: $version) " ).getOrElse(" " )
121
+ report.deprecationWarning(em " inheritance from $psym is deprecated $since$msg" , pos)
122
+ }
123
+
110
124
override def transformValDef (tree : ValDef )(using Context ): ValDef =
111
125
checkDeprecatedOvers(tree)
112
126
checkExperimentalAnnots(tree.symbol)
@@ -122,6 +136,10 @@ class CrossVersionChecks extends MiniPhase:
122
136
checkExperimentalAnnots(tree.symbol)
123
137
tree
124
138
139
+ override def transformTemplate (tree : tpd.Template )(using Context ): tpd.Tree =
140
+ checkDeprecatedInheritance(tree.parents)
141
+ tree
142
+
125
143
override def transformIdent (tree : Ident )(using Context ): Ident = {
126
144
checkUndesiredProperties(tree.symbol, tree.srcPos)
127
145
tree
0 commit comments