Skip to content

Commit 5e2dfdf

Browse files
authored
Merge pull request swiftlang#83714 from tshortli/allow-obsolete-in-swift-overrides
2 parents 5f83862 + 550d7bb commit 5e2dfdf

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,17 +2191,23 @@ static bool checkSingleOverride(ValueDecl *override, ValueDecl *base) {
21912191
auto domain = unavailableAttr.getDomain();
21922192
auto parsedAttr = unavailableAttr.getParsedAttr();
21932193

2194-
if (domain.isPlatform() || domain.isUniversal()) {
2194+
switch (domain.getKind()) {
2195+
case AvailabilityDomain::Kind::Universal:
2196+
case AvailabilityDomain::Kind::SwiftLanguage:
2197+
case AvailabilityDomain::Kind::PackageDescription:
2198+
case AvailabilityDomain::Kind::Platform:
21952199
// FIXME: [availability] Diagnose as an error in a future Swift version.
21962200
break;
2201+
case AvailabilityDomain::Kind::Embedded:
2202+
case AvailabilityDomain::Kind::Custom:
2203+
if (parsedAttr->getLocation().isValid())
2204+
ctx.Diags.diagnose(override, diag::override_unavailable, override)
2205+
.fixItRemove(parsedAttr->getRangeWithAt());
2206+
else
2207+
ctx.Diags.diagnose(override, diag::override_unavailable, override);
2208+
ctx.Diags.diagnose(base, diag::overridden_here);
2209+
break;
21972210
}
2198-
2199-
if (parsedAttr->getLocation().isValid())
2200-
ctx.Diags.diagnose(override, diag::override_unavailable, override)
2201-
.fixItRemove(parsedAttr->getRangeWithAt());
2202-
else
2203-
ctx.Diags.diagnose(override, diag::override_unavailable, override);
2204-
ctx.Diags.diagnose(base, diag::overridden_here);
22052211
break;
22062212
}
22072213
case OverrideAvailability::OverrideLessAvailable: {

test/Availability/availability_unavailable_overrides.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ func testOverrideOfUnavailableDeclFromUnavailableDerivedType() {
239239
}
240240
}
241241

242-
243242
func testImplicitSuperInit() {
244243
// FIXME: The diagnostics for the implicit call to super.init() could be
245244
// relaxed since both initializers are unreachable and the developer cannot
@@ -256,3 +255,19 @@ func testImplicitSuperInit() {
256255
// expected-note@-2 {{call to unavailable initializer 'init()' from superclass 'Base' occurs implicitly at the end of this initializer}}
257256
}
258257
}
258+
259+
func testUnavailableInSwiftOverrides() {
260+
class Base {
261+
func availableMethod() {}
262+
}
263+
264+
class Derived1: Base {
265+
@available(swift, introduced: 99)
266+
override func availableMethod() {}
267+
}
268+
269+
class Derived2: Base {
270+
@available(swift, obsoleted: 1)
271+
override func availableMethod() {}
272+
}
273+
}

test/ClangImporter/objc_override.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ class SomeCellSub5 : SomeCell {
8383
func otherIsEnabled() { } // should not conflict
8484
}
8585

86+
class SomeCellSub6 : SomeCell {
87+
@available(*, unavailable)
88+
@objc override init(string: String) {
89+
super.init(string: string)
90+
}
91+
}
92+
93+
class SomeCellSub7 : SomeCell {
94+
@available(swift, obsoleted: 4)
95+
@objc override init(string: String) {
96+
super.init(string: string)
97+
}
98+
}
99+
86100
class FailSub : FailBase {
87101
override init(value: Int) { try! super.init(value: value) } // expected-error {{overriding a throwing '@objc' initializer with a non-throwing initializer is not supported}}
88102
override class func processValue() {} // expected-error {{overriding a throwing '@objc' method with a non-throwing method is not supported}}

0 commit comments

Comments
 (0)