Skip to content

Commit 098f0a0

Browse files
committed
fix #10247: skip deprecation warn if in synthetic def
1 parent 74a653d commit 098f0a0

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,11 +885,11 @@ object RefChecks {
885885

886886

887887
/** If @deprecated is present, and the point of reference is not enclosed
888-
* in either a deprecated member or a scala bridge method, issue a warning.
888+
* in either a deprecated/synthetic member or a scala bridge method, issue a warning.
889889
*/
890890
private def checkDeprecated(sym: Symbol, pos: SrcPos)(using Context): Unit =
891891
for annot <- sym.getAnnotation(defn.DeprecatedAnnot) do
892-
if !ctx.owner.ownersIterator.exists(_.isDeprecated) then
892+
if !ctx.owner.ownersIterator.exists(owner => owner.isDeprecated || owner.is(Synthetic)) then
893893
val msg = annot.argumentConstant(0).map(": " + _.stringValue).getOrElse("")
894894
val since = annot.argumentConstant(1).map(" since " + _.stringValue).getOrElse("")
895895
report.deprecationWarning(s"${sym.showLocated} is deprecated${since}${msg}", pos)

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class CompilationTests {
5555
compileFile("tests/pos-special/kind-projector.scala", defaultOptions.and("-Ykind-projector")),
5656
compileFile("tests/run/i5606.scala", defaultOptions.and("-Yretain-trees")),
5757
compileFile("tests/pos-custom-args/i5498-postfixOps.scala", defaultOptions withoutLanguageFeature "postfixOps"),
58+
compileFilesInDir("tests/pos-custom-args/deprecation", defaultOptions.and("-deprecation", "-Xfatal-warnings")),
5859
compileFile("tests/pos-custom-args/i8875.scala", defaultOptions.and("-Xprint:getters")),
5960
compileFile("tests/pos-custom-args/i9267.scala", defaultOptions.and("-Ystop-after:erasure")),
6061
compileFile("tests/pos-special/extend-java-enum.scala", defaultOptions.and("-source", "3.0-migration")),
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Color {
2+
def red = Red // error: Red is deprecated
3+
}
4+
5+
enum Color {
6+
@deprecated("no Red", "0.1") case Red
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// check that deprecation warnings of Red are not caught at its definition
2+
enum Color {
3+
@deprecated("no Red", "0.1") case Red
4+
}

0 commit comments

Comments
 (0)