Skip to content

[5.7][ConstraintSystem] Extend availability check to cover unavailable ext… #58487

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 1 commit into from
Apr 28, 2022
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
2 changes: 1 addition & 1 deletion lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6263,7 +6263,7 @@ void ConstraintSystem::diagnoseFailureFor(SolutionApplicationTarget target) {
bool ConstraintSystem::isDeclUnavailable(const Decl *D,
ConstraintLocator *locator) const {
// First check whether this declaration is universally unavailable.
if (D->getAttrs().isUnavailable(getASTContext()))
if (AvailableAttr::isUnavailable(D))
return true;

return TypeChecker::isDeclarationUnavailable(D, DC, [&] {
Expand Down
22 changes: 22 additions & 0 deletions test/Constraints/availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,25 @@ func unavailableFunction(_ x: Int) -> Bool { true } // expected-note {{'unavaila
func sr13260(_ arr: [Int]) {
for x in arr where unavailableFunction(x) {} // expected-error {{'unavailableFunction' is unavailable}}
}

// rdar://92364955 - ambiguity with member declared in unavailable extension
struct WithUnavailableExt {
}

@available(*, unavailable)
extension WithUnavailableExt {
static var foo: WithUnavailableExt = WithUnavailableExt()
}

func test_no_ambiguity_with_unavailable_ext() {
struct A {
static var foo: A = A()
}

struct Test {
init(_: A) {}
init(_: WithUnavailableExt) {}
}

_ = Test(.foo) // Ok `A.foo` since `foo` from `WithUnavailableExt` is unavailable
}