From 4c576e9fc93851e713d0b39f619a213850e2cd19 Mon Sep 17 00:00:00 2001 From: changvvb Date: Mon, 11 Jan 2021 15:16:58 +0800 Subject: [PATCH 1/3] Remove deprecated warning in syntheic def --- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 7 +++++-- tests/pos-special/fatal-warnings/i11022.scala | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 tests/pos-special/fatal-warnings/i11022.scala diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 032cf5930362..a30fdeaac6aa 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -905,16 +905,19 @@ object RefChecks { owner.isDeprecated || isEnumOwner(owner) + def isDeprecatedOrSyntheticMethod(owner: Symbol) = owner.isDeprecated || owner.isAllOf(Method & Synthetic) + /**Scan the chain of outer declaring scopes from the current context * a deprecation warning will be skipped if one the following holds * for a given declaring scope: - * - the symbol associated with the scope is also deprecated. + * - the symbol associated with the scope is also deprecated or synthetic method. * - if and only if `sym` is an enum case, the scope is either * a module that declares `sym`, or the companion class of the * module that declares `sym`. */ def skipWarning(using Context) = - ctx.owner.ownersIterator.exists(if sym.isEnumCase then isDeprecatedOrEnum else _.isDeprecated) + if sym.isEnum then ctx.owner.ownersIterator.exists(isDeprecatedOrEnum) + else ctx.owner.ownersIterator.exists(isDeprecatedOrSyntheticMethod) for annot <- sym.getAnnotation(defn.DeprecatedAnnot) do if !skipWarning then diff --git a/tests/pos-special/fatal-warnings/i11022.scala b/tests/pos-special/fatal-warnings/i11022.scala new file mode 100644 index 000000000000..0c55bfbea54d --- /dev/null +++ b/tests/pos-special/fatal-warnings/i11022.scala @@ -0,0 +1 @@ +@deprecated("no CaseClass", "0.1") case class CaseClass(rgb: Int) \ No newline at end of file From 703019fdfc710ed14cb36d735650c54c94fbfc4a Mon Sep 17 00:00:00 2001 From: changvvb Date: Mon, 11 Jan 2021 19:02:17 +0800 Subject: [PATCH 2/3] Fix tests --- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 4 ++-- tests/pos-special/fatal-warnings/i11022.scala | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index a30fdeaac6aa..e83f7bb75633 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -905,12 +905,12 @@ object RefChecks { owner.isDeprecated || isEnumOwner(owner) - def isDeprecatedOrSyntheticMethod(owner: Symbol) = owner.isDeprecated || owner.isAllOf(Method & Synthetic) + def isDeprecatedOrSyntheticMethod(owner: Symbol) = owner.isDeprecated || (owner.isRealMethod && owner.is(Synthetic)) /**Scan the chain of outer declaring scopes from the current context * a deprecation warning will be skipped if one the following holds * for a given declaring scope: - * - the symbol associated with the scope is also deprecated or synthetic method. + * - the symbol associated with the scope is also deprecated or synthetic real method. * - if and only if `sym` is an enum case, the scope is either * a module that declares `sym`, or the companion class of the * module that declares `sym`. diff --git a/tests/pos-special/fatal-warnings/i11022.scala b/tests/pos-special/fatal-warnings/i11022.scala index 0c55bfbea54d..8714c93a40f7 100644 --- a/tests/pos-special/fatal-warnings/i11022.scala +++ b/tests/pos-special/fatal-warnings/i11022.scala @@ -1 +1 @@ -@deprecated("no CaseClass", "0.1") case class CaseClass(rgb: Int) \ No newline at end of file +@deprecated("no CaseClass", "0.1") case class CaseClass(rgb: Int) From 4526a80b149de19afebbd5704388af840ea0cf29 Mon Sep 17 00:00:00 2001 From: changvvb Date: Mon, 11 Jan 2021 19:42:14 +0800 Subject: [PATCH 3/3] Update for review --- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index e83f7bb75633..c875b0707630 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -902,7 +902,7 @@ object RefChecks { def isDeprecatedOrEnum(owner: Symbol)(using Context) = // pre: sym is an enumcase - owner.isDeprecated + isDeprecatedOrSyntheticMethod(owner) || isEnumOwner(owner) def isDeprecatedOrSyntheticMethod(owner: Symbol) = owner.isDeprecated || (owner.isRealMethod && owner.is(Synthetic)) @@ -916,8 +916,7 @@ object RefChecks { * module that declares `sym`. */ def skipWarning(using Context) = - if sym.isEnum then ctx.owner.ownersIterator.exists(isDeprecatedOrEnum) - else ctx.owner.ownersIterator.exists(isDeprecatedOrSyntheticMethod) + ctx.owner.ownersIterator.exists(if sym.isEnumCase then isDeprecatedOrEnum else isDeprecatedOrSyntheticMethod) for annot <- sym.getAnnotation(defn.DeprecatedAnnot) do if !skipWarning then