Skip to content

Commit 6aa8e82

Browse files
authored
Merge pull request #86024 from xedin/rdar-163562182
[DeclChecker] Skip contextualization of initializers associated with …
2 parents babf2dd + 5e815b9 commit 6aa8e82

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,6 +2706,15 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
27062706
if (!PBD->isInitialized(i))
27072707
continue;
27082708

2709+
if (PBD->isInitializerSubsumed(i)) {
2710+
auto *var = PBD->getSingleVar();
2711+
// The initializer of a property wrapped variable gets transferred
2712+
// the synthesized backing storage property, let have it contextualized
2713+
// there.
2714+
if (var && var->hasAttachedPropertyWrapper())
2715+
continue;
2716+
}
2717+
27092718
if (!PBD->isInitializerChecked(i)) {
27102719
TypeCheckExprOptions options;
27112720

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
enum CustomError: Error {
4+
}
5+
6+
struct ValidationError: Error {
7+
}
8+
9+
func parseOption(_: String) throws -> Int {
10+
42
11+
}
12+
13+
@propertyWrapper
14+
public struct Option<Value> {
15+
public var wrappedValue: Value
16+
17+
public init(
18+
wrappedValue: Value,
19+
transform: @Sendable @escaping (String) throws -> Value
20+
) {
21+
self.wrappedValue = wrappedValue
22+
}
23+
}
24+
25+
struct Test {
26+
@Option(transform: {
27+
do {
28+
return try parseOption($0)
29+
} catch let error as CustomError {
30+
throw ValidationError()
31+
}
32+
})
33+
var prop: Int = 0
34+
}

0 commit comments

Comments
 (0)