Skip to content

Commit fb8c6bd

Browse files
committed
Sema: Correctly handle static 'let's in VarDecl::isSettable
1 parent ab9608b commit fb8c6bd

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/AST/Decl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5663,6 +5663,11 @@ bool VarDecl::isSettable(const DeclContext *UseDC,
56635663
if (!isLet())
56645664
return supportsMutation();
56655665

5666+
// Static 'let's are always immutable.
5667+
if (isStatic()) {
5668+
return false;
5669+
}
5670+
56665671
//
56675672
// All the remaining logic handles the special cases where you can
56685673
// assign a 'let'.

test/decl/protocol/protocol_enum_witness.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,10 @@ protocol MissingAccessorsVar {
146146
enum Bar14: MissingAccessorsVar { // OK
147147
case bar
148148
}
149+
150+
protocol MissingAccessorsLet {
151+
static let bar: Self // expected-error {{protocols cannot require properties to be immutable; declare read-only properties by using 'var' with a '{ get }' specifier}}
152+
}
153+
enum Bar15: MissingAccessorsLet { // OK
154+
case bar
155+
}

0 commit comments

Comments
 (0)