Skip to content

Commit 60b5564

Browse files
authored
Merge pull request #3467 from CodaFi/inherited-wealth-and-ancillary-diagnostic-relief-claims
[SE-2007][Sema] Don't subject protocol 'Self' to availability checks in lookup
2 parents 09367a5 + 2bcb862 commit 60b5564

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,18 @@ void TypeChecker::checkInheritanceClause(Decl *decl,
271271
} else if (auto ext = dyn_cast<ExtensionDecl>(decl)) {
272272
DC = ext;
273273
options |= TR_GenericSignature | TR_InheritanceClause;
274-
} else if (isa<GenericTypeParamDecl>(decl)) {
274+
} else if (auto GP = dyn_cast<GenericTypeParamDecl>(decl)) {
275275
// For generic parameters, we want name lookup to look at just the
276276
// signature of the enclosing entity.
277277
DC = decl->getDeclContext();
278278
if (auto nominal = dyn_cast<NominalTypeDecl>(DC)) {
279279
DC = nominal;
280280
options |= TR_GenericSignature;
281+
// When looking up protocol 'Self' accessibility checks are disabled to
282+
// head off spurious unavailable diagnostics.
283+
if (isa<ProtocolDecl>(DC) && GP->isProtocolSelf()) {
284+
options |= TR_AllowUnavailable;
285+
}
281286
} else if (auto ext = dyn_cast<ExtensionDecl>(DC)) {
282287
DC = ext;
283288
options |= TR_GenericSignature;

test/attr/attr_availability.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ typealias int = Int // expected-note {{'int' has been explicitly marked unavaila
3131
@available(*, unavailable, renamed: "Float")
3232
typealias float = Float // expected-note {{'float' has been explicitly marked unavailable here}}
3333

34+
protocol MyNewerProtocol {}
35+
36+
@available(*, unavailable, renamed: "MyNewerProtocol")
37+
protocol MyOlderProtocol {} // expected-note {{'MyOlderProtocol' has been explicitly marked unavailable here}}
38+
39+
extension Int: MyOlderProtocol {} // expected-error {{'MyOlderProtocol' has been renamed to 'MyNewerProtocol'}}
40+
3441
struct MyCollection<Element> {
3542
@available(*, unavailable, renamed: "Element")
3643
typealias T = Element // expected-note 2{{'T' has been explicitly marked unavailable here}}

0 commit comments

Comments
 (0)