Skip to content

[Typechecker] Check conforming protocols of context when resolving a custom attribute #26795

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 4 commits into from
Aug 30, 2019
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
4 changes: 3 additions & 1 deletion lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,9 @@ static DirectlyReferencedTypeDecls
directReferencesForUnqualifiedTypeLookup(DeclName name,
SourceLoc loc, DeclContext *dc) {
DirectlyReferencedTypeDecls results;
UnqualifiedLookup::Options options = UnqualifiedLookup::Flags::TypeLookup;
UnqualifiedLookup::Options options =
UnqualifiedLookup::Flags::TypeLookup |
UnqualifiedLookup::Flags::AllowProtocolMembers;
UnqualifiedLookup lookup(name, dc, loc, options);
for (const auto &result : lookup.Results) {
if (auto typeDecl = dyn_cast<TypeDecl>(result.getValueDecl()))
Expand Down
62 changes: 62 additions & 0 deletions test/decl/var/property_wrappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1519,3 +1519,65 @@ func test_missing_method_with_lvalue_base() {
}
}
}

// SR-11288
// Look into the protocols that the type conforms to

// typealias as propertyWrapper //

@propertyWrapper
struct SR_11288_S0 {
var wrappedValue: Int
}

protocol SR_11288_P1 {
typealias SR_11288_Wrapper1 = SR_11288_S0
}

struct SR_11288_S1: SR_11288_P1 {
@SR_11288_Wrapper1 var answer = 42 // Okay
}

// associatedtype as propertyWrapper //

protocol SR_11288_P2 {
associatedtype SR_11288_Wrapper2 = SR_11288_S0
}

struct SR_11288_S2: SR_11288_P2 {
@SR_11288_Wrapper2 var answer = 42 // expected-error {{unknown attribute 'SR_11288_Wrapper2'}}
}

protocol SR_11288_P3 {
associatedtype SR_11288_Wrapper3
}

struct SR_11288_S3: SR_11288_P3 {
typealias SR_11288_Wrapper3 = SR_11288_S0
@SR_11288_Wrapper3 var answer = 42 // Okay
}

// typealias as propertyWrapper in a constrained protocol extension //

protocol SR_11288_P4 {}
extension SR_11288_P4 where Self: AnyObject {
typealias SR_11288_Wrapper4 = SR_11288_S0
}

struct SR_11288_S4: SR_11288_P4 {
@SR_11288_Wrapper4 var answer = 42 // expected-error 2 {{'SR_11288_S4.SR_11288_Wrapper4.Type' (aka 'SR_11288_S0.Type') requires that 'SR_11288_S4' conform to 'AnyObject'}}
}

class SR_11288_C0: SR_11288_P4 {
@SR_11288_Wrapper4 var answer = 42 // Okay
}

// typealias as propertyWrapper in a generic type //

protocol SR_11288_P5 {
typealias SR_11288_Wrapper5 = SR_11288_S0
}

struct SR_11288_S5<T>: SR_11288_P5 {
@SR_11288_Wrapper5 var answer = 42 // Okay
}