Skip to content

Sema: Allow unavailable conformances to be referenced from unavailable contexts #37233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
3 changes: 2 additions & 1 deletion lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,8 @@ static bool isInsideCompatibleUnavailableDeclaration(
// but allow the use of types.
PlatformKind platform = attr->Platform;
if (platform == PlatformKind::none &&
!isa<TypeDecl>(D)) {
!isa<TypeDecl>(D) &&
!isa<ExtensionDecl>(D)) {
return false;
}

Expand Down
20 changes: 16 additions & 4 deletions test/Sema/conformance_availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct HasUnavailableConformance1 {}

@available(*, unavailable)
extension HasUnavailableConformance1 : Horse {}
// expected-note@-1 7{{conformance of 'HasUnavailableConformance1' to 'Horse' has been explicitly marked unavailable here}}
// expected-note@-1 4{{conformance of 'HasUnavailableConformance1' to 'Horse' has been explicitly marked unavailable here}}

func passUnavailableConformance1(x: HasUnavailableConformance1) {
takesHorse(x) // expected-error {{conformance of 'HasUnavailableConformance1' to 'Horse' is unavailable}}
Expand All @@ -26,9 +26,9 @@ func passUnavailableConformance1(x: HasUnavailableConformance1) {

@available(*, unavailable)
func passUnavailableConformance1a(x: HasUnavailableConformance1) {
takesHorse(x) // expected-error {{conformance of 'HasUnavailableConformance1' to 'Horse' is unavailable}}
x.giddyUp() // expected-error {{conformance of 'HasUnavailableConformance1' to 'Horse' is unavailable}}
_ = UsesHorse<HasUnavailableConformance1>.self // expected-error {{conformance of 'HasUnavailableConformance1' to 'Horse' is unavailable}}
takesHorse(x)
x.giddyUp()
_ = UsesHorse<HasUnavailableConformance1>.self
}

// Platform unavailability
Expand Down Expand Up @@ -351,3 +351,15 @@ extension Car {
@available(macOS 100, *)
extension ClownCar : Vehicle {}
// expected-error@-1 {{protocol 'Vehicle' requires 'move()' to be available in macOS 100 and newer}}

// rdar://problem/75430966 - Allow using unavailable conformances from unavailable contexts.
@available(*, unavailable)
public enum UnavailableEnum {
case horse
}

@available(*, unavailable)
extension UnavailableEnum : Swift.Equatable {}

@available(*, unavailable)
extension UnavailableEnum : Swift.Hashable {}