Skip to content

Commit d219829

Browse files
authored
Merge pull request swiftlang#26795 from theblixguy/fix/SR-11288
[Typechecker] Check conforming protocols of context when resolving a custom attribute
2 parents 88f8592 + acba675 commit d219829

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

lib/AST/NameLookup.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,9 @@ static DirectlyReferencedTypeDecls
18571857
directReferencesForUnqualifiedTypeLookup(DeclName name,
18581858
SourceLoc loc, DeclContext *dc) {
18591859
DirectlyReferencedTypeDecls results;
1860-
UnqualifiedLookup::Options options = UnqualifiedLookup::Flags::TypeLookup;
1860+
UnqualifiedLookup::Options options =
1861+
UnqualifiedLookup::Flags::TypeLookup |
1862+
UnqualifiedLookup::Flags::AllowProtocolMembers;
18611863
UnqualifiedLookup lookup(name, dc, loc, options);
18621864
for (const auto &result : lookup.Results) {
18631865
if (auto typeDecl = dyn_cast<TypeDecl>(result.getValueDecl()))

test/decl/var/property_wrappers.swift

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,3 +1519,65 @@ func test_missing_method_with_lvalue_base() {
15191519
}
15201520
}
15211521
}
1522+
1523+
// SR-11288
1524+
// Look into the protocols that the type conforms to
1525+
1526+
// typealias as propertyWrapper //
1527+
1528+
@propertyWrapper
1529+
struct SR_11288_S0 {
1530+
var wrappedValue: Int
1531+
}
1532+
1533+
protocol SR_11288_P1 {
1534+
typealias SR_11288_Wrapper1 = SR_11288_S0
1535+
}
1536+
1537+
struct SR_11288_S1: SR_11288_P1 {
1538+
@SR_11288_Wrapper1 var answer = 42 // Okay
1539+
}
1540+
1541+
// associatedtype as propertyWrapper //
1542+
1543+
protocol SR_11288_P2 {
1544+
associatedtype SR_11288_Wrapper2 = SR_11288_S0
1545+
}
1546+
1547+
struct SR_11288_S2: SR_11288_P2 {
1548+
@SR_11288_Wrapper2 var answer = 42 // expected-error {{unknown attribute 'SR_11288_Wrapper2'}}
1549+
}
1550+
1551+
protocol SR_11288_P3 {
1552+
associatedtype SR_11288_Wrapper3
1553+
}
1554+
1555+
struct SR_11288_S3: SR_11288_P3 {
1556+
typealias SR_11288_Wrapper3 = SR_11288_S0
1557+
@SR_11288_Wrapper3 var answer = 42 // Okay
1558+
}
1559+
1560+
// typealias as propertyWrapper in a constrained protocol extension //
1561+
1562+
protocol SR_11288_P4 {}
1563+
extension SR_11288_P4 where Self: AnyObject {
1564+
typealias SR_11288_Wrapper4 = SR_11288_S0
1565+
}
1566+
1567+
struct SR_11288_S4: SR_11288_P4 {
1568+
@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'}}
1569+
}
1570+
1571+
class SR_11288_C0: SR_11288_P4 {
1572+
@SR_11288_Wrapper4 var answer = 42 // Okay
1573+
}
1574+
1575+
// typealias as propertyWrapper in a generic type //
1576+
1577+
protocol SR_11288_P5 {
1578+
typealias SR_11288_Wrapper5 = SR_11288_S0
1579+
}
1580+
1581+
struct SR_11288_S5<T>: SR_11288_P5 {
1582+
@SR_11288_Wrapper5 var answer = 42 // Okay
1583+
}

0 commit comments

Comments
 (0)