Skip to content

[ConstraintSystem] Mark type variable representing closure parameter … #34918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/Sema/CSBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ bool ConstraintSystem::PotentialBindings::isPotentiallyIncomplete() const {
return true;
}

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

return false;
}

Expand Down
28 changes: 28 additions & 0 deletions test/Constraints/rdar71858936.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %target-typecheck-verify-swift

@propertyWrapper
@dynamicMemberLookup
struct Binding<Value> {
var wrappedValue: Value

init(get: @escaping () -> Value, set: @escaping (Value) -> Void) {
self.wrappedValue = get()
}

subscript<Subject>(dynamicMember keyPath: WritableKeyPath<Value, Subject>) -> Binding<Subject> {
get { fatalError() }
}
}

class S {
var value: String = ""
var buffer: String? = nil

var body: String {
let binding = Binding(
get: { self.buffer ?? self.value },
set: { self.buffer = $0 }
)
return binding.wrappedValue
}
}