Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions lib/Sema/TypeCheckDeclOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
17 changes: 16 additions & 1 deletion test/Availability/availability_unavailable_overrides.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {}
}
}
14 changes: 14 additions & 0 deletions test/ClangImporter/objc_override.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down