Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 22668 - Don't errors when a deprecated method overrides another one
Because both declarations acknowledge that the declaration is deprecated. This is especially important for libraries that provide a collection of classes and want to deprecate certain method throughout the entire class hierarchy.
- Loading branch information
1 parent
2b6ac27
commit eb9c1b9
Showing
2 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// https://issues.dlang.org/show_bug.cgi?id=22668 | ||
|
||
// Overrides with same deprecated'ness are allowed | ||
|
||
class SameParent | ||
{ | ||
deprecated void foo() {} | ||
void foo(int) {} | ||
|
||
void bar(int) {} | ||
deprecated void bar() {} | ||
} | ||
|
||
class SameChild : SameParent | ||
{ | ||
deprecated override void foo() {} | ||
override void foo(int) {} | ||
|
||
override void bar(int) {} | ||
deprecated override void bar() {} | ||
} | ||
|
||
/** | ||
Only the parent declaration is deprecated | ||
TEST_OUTPUT: | ||
---- | ||
compilable/deprecated_override.d(44): Deprecation: `deprecated_override.IntroducingChild.foo` is overriding the deprecated method `deprecated_override.IntroducingParent.foo` | ||
compilable/deprecated_override.d(48): Deprecation: `deprecated_override.IntroducingChild.bar` is overriding the deprecated method `deprecated_override.IntroducingParent.bar` | ||
---- | ||
**/ | ||
|
||
class IntroducingParent | ||
{ | ||
deprecated void foo() {} | ||
void foo(int) {} | ||
|
||
void bar(int) {} | ||
deprecated void bar() {} | ||
} | ||
|
||
class IntroducingChild : IntroducingParent | ||
{ | ||
override void foo() {} | ||
override void foo(int) {} | ||
|
||
override void bar(int) {} | ||
override void bar() {} | ||
} | ||
|
||
// Unrelated to this path but should this error as well? | ||
|
||
class IntroducingGrandchild : IntroducingChild | ||
{ | ||
override void foo() {} | ||
override void foo(int) {} | ||
|
||
override void bar(int) {} | ||
override void bar() {} | ||
} | ||
|
||
/** | ||
Only the overriding declaration is deprecated | ||
TEST_OUTPUT: | ||
---- | ||
compilable/deprecated_override.d(83): Deprecation: `deprecated_override.OverrideChild.foo` cannot be marked as `deprecated` because it is overriding a function in the base class | ||
compilable/deprecated_override.d(87): Deprecation: `deprecated_override.OverrideChild.bar` cannot be marked as `deprecated` because it is overriding a function in the base class | ||
---- | ||
**/ | ||
|
||
class OverrideParent | ||
{ | ||
void foo() {} | ||
void foo(int) {} | ||
|
||
void bar(int) {} | ||
void bar() {} | ||
} | ||
|
||
class OverrideChild : OverrideParent | ||
{ | ||
deprecated override void foo() {} | ||
override void foo(int) {} | ||
|
||
override void bar(int) {} | ||
deprecated override void bar() {} | ||
} | ||
|
||
class OverrideGrandChild : OverrideChild | ||
{ | ||
deprecated override void foo() {} | ||
override void foo(int) {} | ||
|
||
override void bar(int) {} | ||
deprecated override void bar() {} | ||
} |