Skip to content

Commit 2736d53

Browse files
authored
Merge pull request #27311 from theblixguy/fix/SR-11509
[Typechecker] Perform capture analysis for enums as well
2 parents 03bdd1c + 9c97153 commit 2736d53

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2587,6 +2587,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
25872587

25882588
checkAccessControl(TC, ED);
25892589

2590+
TC.checkPatternBindingCaptures(ED);
2591+
25902592
if (ED->hasRawType() && !ED->isObjC()) {
25912593
// ObjC enums have already had their raw values checked, but pure Swift
25922594
// enums haven't.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-swift-frontend %s -typecheck -verify
2+
3+
@propertyWrapper
4+
public struct Wrapper<Value> {
5+
public init(someValue unused: Int) {
6+
_ = unused
7+
}
8+
9+
public var wrappedValue: Value?
10+
}
11+
12+
13+
func functionScope() {
14+
let scopedValue = 3 // expected-note {{'scopedValue' declared here}}
15+
// expected-warning@-1 {{initialization of immutable value 'scopedValue' was never used; consider replacing with assignment to '_' or removing it}}
16+
17+
enum StaticScope { // expected-note {{type declared here}}
18+
@Wrapper(someValue: scopedValue) static var foo: String? // expected-error {{enum declaration cannot close over value 'scopedValue' defined in outer scope}}
19+
}
20+
21+
_ = StaticScope.foo
22+
}

0 commit comments

Comments
 (0)