Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit 8655ce5

Browse files
committed
Merge branch 'main' of github.com:apple/swift into tensorflow-stage
* 'main' of github.com:apple/swift: [ConstraintSystem] Mark type variable representing closure parameter (in the body) as incomplete
2 parents 40ed6d3 + 1a20cbe commit 8655ce5

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@ bool ConstraintSystem::PotentialBindings::isPotentiallyIncomplete() const {
8888
return true;
8989
}
9090

91+
// If there is a `bind param` constraint associated with
92+
// current type variable, result should be aware of that
93+
// fact. Binding set might be incomplete until
94+
// this constraint is resolved, because we currently don't
95+
// look-through constraints expect to `subtype` to try and
96+
// find related bindings.
97+
// This only affects type variable that appears one the
98+
// right-hand side of the `bind param` constraint and
99+
// represents result type of the closure body, because
100+
// left-hand side gets types from overload choices.
101+
if (llvm::any_of(
102+
EquivalentTo,
103+
[&](const std::pair<TypeVariableType *, Constraint *> &equivalence) {
104+
auto *constraint = equivalence.second;
105+
return constraint->getKind() == ConstraintKind::BindParam &&
106+
constraint->getSecondType()->isEqual(TypeVar);
107+
}))
108+
return true;
109+
91110
return false;
92111
}
93112

test/Constraints/rdar71858936.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
@propertyWrapper
4+
@dynamicMemberLookup
5+
struct Binding<Value> {
6+
var wrappedValue: Value
7+
8+
init(get: @escaping () -> Value, set: @escaping (Value) -> Void) {
9+
self.wrappedValue = get()
10+
}
11+
12+
subscript<Subject>(dynamicMember keyPath: WritableKeyPath<Value, Subject>) -> Binding<Subject> {
13+
get { fatalError() }
14+
}
15+
}
16+
17+
class S {
18+
var value: String = ""
19+
var buffer: String? = nil
20+
21+
var body: String {
22+
let binding = Binding(
23+
get: { self.buffer ?? self.value },
24+
set: { self.buffer = $0 }
25+
)
26+
return binding.wrappedValue
27+
}
28+
}

0 commit comments

Comments
 (0)