Merge pull request #83714 from tshortli/allow-obsolete-in-swift-overrides

This commit is contained in:
Allan Shortlidge
2025-08-14 07:16:50 -07:00
committed by GitHub
3 changed files with 44 additions and 9 deletions

View File

@@ -2191,17 +2191,23 @@ static bool checkSingleOverride(ValueDecl *override, ValueDecl *base) {
auto domain = unavailableAttr.getDomain();
auto parsedAttr = unavailableAttr.getParsedAttr();
if (domain.isPlatform() || domain.isUniversal()) {
switch (domain.getKind()) {
case AvailabilityDomain::Kind::Universal:
case AvailabilityDomain::Kind::SwiftLanguage:
case AvailabilityDomain::Kind::PackageDescription:
case AvailabilityDomain::Kind::Platform:
// FIXME: [availability] Diagnose as an error in a future Swift version.
break;
case AvailabilityDomain::Kind::Embedded:
case AvailabilityDomain::Kind::Custom:
if (parsedAttr->getLocation().isValid())
ctx.Diags.diagnose(override, diag::override_unavailable, override)
.fixItRemove(parsedAttr->getRangeWithAt());
else
ctx.Diags.diagnose(override, diag::override_unavailable, override);
ctx.Diags.diagnose(base, diag::overridden_here);
break;
}
if (parsedAttr->getLocation().isValid())
ctx.Diags.diagnose(override, diag::override_unavailable, override)
.fixItRemove(parsedAttr->getRangeWithAt());
else
ctx.Diags.diagnose(override, diag::override_unavailable, override);
ctx.Diags.diagnose(base, diag::overridden_here);
break;
}
case OverrideAvailability::OverrideLessAvailable: {

View File

@@ -239,7 +239,6 @@ func testOverrideOfUnavailableDeclFromUnavailableDerivedType() {
}
}
func testImplicitSuperInit() {
// FIXME: The diagnostics for the implicit call to super.init() could be
// relaxed since both initializers are unreachable and the developer cannot
@@ -256,3 +255,19 @@ func testImplicitSuperInit() {
// expected-note@-2 {{call to unavailable initializer 'init()' from superclass 'Base' occurs implicitly at the end of this initializer}}
}
}
func testUnavailableInSwiftOverrides() {
class Base {
func availableMethod() {}
}
class Derived1: Base {
@available(swift, introduced: 99)
override func availableMethod() {}
}
class Derived2: Base {
@available(swift, obsoleted: 1)
override func availableMethod() {}
}
}

View File

@@ -83,6 +83,20 @@ class SomeCellSub5 : SomeCell {
func otherIsEnabled() { } // should not conflict
}
class SomeCellSub6 : SomeCell {
@available(*, unavailable)
@objc override init(string: String) {
super.init(string: string)
}
}
class SomeCellSub7 : SomeCell {
@available(swift, obsoleted: 4)
@objc override init(string: String) {
super.init(string: string)
}
}
class FailSub : FailBase {
override init(value: Int) { try! super.init(value: value) } // expected-error {{overriding a throwing '@objc' initializer with a non-throwing initializer is not supported}}
override class func processValue() {} // expected-error {{overriding a throwing '@objc' method with a non-throwing method is not supported}}