Skip to content

Commit 066bbd1

Browse files
committed
[CSClosure] Fix handling of property wrapped pattern bindings
Property wrappers trigger initializer synthesis. Synthesized initializers should not be re-typechecked when encountered e.g. while re-solving closure with a different contextual type. Resolves: #59294 Resolves: rdar://94506352
1 parent e63df1e commit 066bbd1

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

lib/Sema/CSApply.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8892,6 +8892,9 @@ ExprWalker::rewriteTarget(SolutionApplicationTarget target) {
88928892
} else if (auto patternBinding = target.getAsPatternBinding()) {
88938893
ConstraintSystem &cs = solution.getConstraintSystem();
88948894
for (unsigned index : range(patternBinding->getNumPatternEntries())) {
8895+
if (patternBinding->isInitializerChecked(index))
8896+
continue;
8897+
88958898
// Find the solution application target for this.
88968899
auto knownTarget = *cs.getSolutionApplicationTarget(
88978900
{patternBinding, index});

lib/Sema/CSClosure.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ class SyntacticElementConstraintGenerator
427427
locator, LocatorPathElt::SyntacticElement(patternBinding));
428428

429429
for (unsigned index : range(patternBinding->getNumPatternEntries())) {
430+
if (patternBinding->isInitializerChecked(index))
431+
continue;
432+
430433
auto *pattern = TypeChecker::resolvePattern(
431434
patternBinding->getPattern(index), patternBinding->getDeclContext(),
432435
/*isStmtCondition=*/true);
@@ -502,6 +505,9 @@ class SyntacticElementConstraintGenerator
502505
locator->castLastElementTo<LocatorPathElt::PatternBindingElement>()
503506
.getIndex();
504507

508+
if (patternBinding->isInitializerChecked(index))
509+
return;
510+
505511
auto contextualPattern =
506512
ContextualPattern::forPatternBindingDecl(patternBinding, index);
507513
Type patternType = TypeChecker::typeCheckPattern(contextualPattern);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// https://github.com/apple/swift/issues/59294
4+
5+
@propertyWrapper
6+
struct WrapperValue<Value> {
7+
var value: Value
8+
init(wrappedValue: Value) {
9+
self.value = wrappedValue
10+
}
11+
12+
var projectedValue: Self {
13+
return self
14+
}
15+
16+
var wrappedValue: Value {
17+
get {
18+
self.value
19+
}
20+
set {
21+
self.value = newValue
22+
}
23+
}
24+
25+
func printValue() {
26+
print(value)
27+
}
28+
}
29+
30+
31+
class Test {
32+
static func test() {
33+
return [0, 1, 2].compactMap { _ in // expected-error {{unexpected non-void return value in void function}} expected-note {{did you mean to add a return type?}}
34+
@WrapperValue var value: Bool? = false
35+
if value != nil {
36+
return false
37+
}
38+
39+
return value ?? false
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)