File tree 5 files changed +43
-4
lines changed
compiler/src/dotty/tools/dotc
neg-custom-args/deprecation
5 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -604,6 +604,7 @@ object Flags {
604
604
val Scala2Trait : FlagSet = Scala2x | Trait
605
605
val SyntheticArtifact : FlagSet = Synthetic | Artifact
606
606
val SyntheticCase : FlagSet = Synthetic | Case
607
+ val SyntheticMethod : FlagSet = Synthetic | Method
607
608
val SyntheticModule : FlagSet = Synthetic | Module
608
609
val SyntheticOpaque : FlagSet = Synthetic | Opaque
609
610
val SyntheticParam : FlagSet = Synthetic | Param
Original file line number Diff line number Diff line change @@ -49,18 +49,22 @@ class CrossVersionChecks extends MiniPhase:
49
49
owner.isDeprecated
50
50
|| isEnumOwner(owner)
51
51
52
- /** Scan the chain of outer declaring scopes from the current context
52
+ /** Skip warnings for synthetic members of case classes during declaration and
53
+ * scan the chain of outer declaring scopes from the current context
53
54
* a deprecation warning will be skipped if one the following holds
54
55
* for a given declaring scope:
55
56
* - the symbol associated with the scope is also deprecated.
56
57
* - if and only if `sym` is an enum case, the scope is either
57
58
* a module that declares `sym`, or the companion class of the
58
59
* module that declares `sym`.
59
60
*/
60
- def skipWarning (using Context ) =
61
- ctx.owner.ownersIterator.exists(if sym.isEnumCase then isDeprecatedOrEnum else _.isDeprecated)
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)
62
64
63
- for annot <- sym.getAnnotation(defn.DeprecatedAnnot ) do
65
+ // Also check for deprecation of the companion class for synthetic methods
66
+ val toCheck = sym :: (if sym.isAllOf(SyntheticMethod ) then sym.owner.companionClass :: Nil else Nil )
67
+ for sym <- toCheck; annot <- sym.getAnnotation(defn.DeprecatedAnnot ) do
64
68
if ! skipWarning then
65
69
val msg = annot.argumentConstant(0 ).map(" : " + _.stringValue).getOrElse(" " )
66
70
val since = annot.argumentConstant(1 ).map(" since " + _.stringValue).getOrElse(" " )
Original file line number Diff line number Diff line change
1
+ -- Error: tests/neg-custom-args/deprecation/i11022.scala:8:7 -----------------------------------------------------------
2
+ 8 |val a: CaseClass = CaseClass(42) // error: deprecated type // error: deprecated apply method
3
+ | ^^^^^^^^^
4
+ | class CaseClass is deprecated: no CaseClass
5
+ -- Error: tests/neg-custom-args/deprecation/i11022.scala:8:19 ----------------------------------------------------------
6
+ 8 |val a: CaseClass = CaseClass(42) // error: deprecated type // error: deprecated apply method
7
+ | ^^^^^^^^^
8
+ | class CaseClass is deprecated: no CaseClass
9
+ -- Error: tests/neg-custom-args/deprecation/i11022.scala:9:7 -----------------------------------------------------------
10
+ 9 |val b: CaseClass = new CaseClass(42) // error: deprecated type // error: deprecated class
11
+ | ^^^^^^^^^
12
+ | class CaseClass is deprecated: no CaseClass
13
+ -- Error: tests/neg-custom-args/deprecation/i11022.scala:9:23 ----------------------------------------------------------
14
+ 9 |val b: CaseClass = new CaseClass(42) // error: deprecated type // error: deprecated class
15
+ | ^^^^^^^^^
16
+ | class CaseClass is deprecated: no CaseClass
17
+ -- Error: tests/neg-custom-args/deprecation/i11022.scala:10:14 ---------------------------------------------------------
18
+ 10 |val c: Unit = CaseClass(42).magic() // error: deprecated apply method
19
+ | ^^^^^^^^^
20
+ | class CaseClass is deprecated: no CaseClass
Original file line number Diff line number Diff line change
1
+ @ deprecated(" no CaseClass" )
2
+ case class CaseClass (rgb : Int ):
3
+ def magic (): Unit = ()
4
+
5
+ object CaseClass :
6
+ def notDeprecated (): Unit = ()
7
+
8
+ val a : CaseClass = CaseClass (42 ) // error: deprecated type // error: deprecated apply method
9
+ val b : CaseClass = new CaseClass (42 ) // error: deprecated type // error: deprecated class
10
+ val c : Unit = CaseClass (42 ).magic() // error: deprecated apply method
11
+ val d : Unit = CaseClass .notDeprecated() // compiles
Original file line number Diff line number Diff line change
1
+ // scalac: -Werror -deprecation
2
+ @ deprecated(" no CaseClass" )
3
+ case class CaseClass (rgb : Int )
You can’t perform that action at this time.
0 commit comments