Skip to content

Commit 52e301e

Browse files
committed
Fix isProtocolContext condition
1 parent 66de676 commit 52e301e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2652,7 +2652,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
26522652
// @_staticExclusiveOnly types cannot be put into 'var's, only 'let'.
26532653
if (auto SD = VD->getInterfaceType()->getStructOrBoundGenericStruct()) {
26542654
if (SD->getAttrs().hasAttribute<StaticExclusiveOnlyAttr>()) {
2655-
auto isProtocolContext = DC->getSelfProtocolDecl() != nullptr;
2655+
auto isProtocolContext = isa<ProtocolDecl>(DC);
26562656

26572657
if (isProtocolContext && !VD->supportsMutation()) {
26582658
return;

test/attr/attr_static_exclusive_only.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ struct B: ~Copyable { // expected-note {{'B' is a non-mutable type}}
1111
// expected-note@-4 {{'B' is a non-mutable type}}
1212
// expected-note@-5 {{'B' is a non-mutable type}}
1313
// expected-note@-6 {{'B' is a non-mutable type}}
14+
// expected-note@-7 {{'B' is a non-mutable type}}
1415
mutating func change() { // expected-error {{type 'B' cannot have mutating function 'change()'}}
1516
print("123")
1617
}
@@ -92,3 +93,9 @@ extension W: U {
9293
struct X: ~Copyable, U {
9394
let v: B // OK
9495
}
96+
97+
extension U {
98+
var y: B { // expected-error {{variable of type 'B' must be declared with a 'let'}}
99+
B()
100+
}
101+
}

0 commit comments

Comments
 (0)