Skip to content

[CSBindings] Prevent BindingSet::isViable from dropping viable bindings #76487

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
Sep 17, 2024
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
10 changes: 10 additions & 0 deletions lib/Sema/CSBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,16 @@ bool BindingSet::isViable(PotentialBinding &binding, bool isTransitive) {
if (!existingNTD || NTD != existingNTD)
continue;

// What is going on here needs to be thoroughly re-evaluated,
// but at least for now, let's not filter bindings of different
// kinds so if we have a situation like: `Array<$T0> conv $T1`
// and `$T1 conv Array<(String, Int)>` we can't lose `Array<$T0>`
// as a binding because `$T0` could be inferred to
// `(key: String, value: Int)` and binding `$T1` to `Array<(String, Int)>`
// eagerly would be incorrect.
if (existing->Kind != binding.Kind)
continue;

// If new type has a type variable it shouldn't
// be considered viable.
if (type->hasTypeVariable())
Expand Down
10 changes: 10 additions & 0 deletions test/Constraints/array_literal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,13 @@ do {
]
}
}


do {
func f<R>(fn: () -> [R]) -> [R] { [] }

// Requires collection upcast from Array<(key: String, value: String)> to `Array<(String, String)>`
func g(v: [String: String]) {
let _: [(String, String)] = f { return Array(v) } + v // Ok
}
}
4 changes: 2 additions & 2 deletions validation-test/Sema/SwiftUI/rdar98862079.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct MyView : View {

var body: some View {
test(value: true ? $newBounds.maxBinding : $newBounds.minBinding, in: bounds)
// expected-error@-1 2 {{result values in '? :' expression have mismatching types 'Binding<Binding<Double>?>' and 'Binding<Double>'}}
// expected-note@-2 2 {{arguments to generic parameter 'Value' ('Binding<Double>?' and 'Double') are expected to be equal}}
// expected-error@-1 {{cannot convert value of type 'Binding<Binding<Double>?>' to expected argument type 'Binding<Double>'}}
// expected-note@-2 {{arguments to generic parameter 'Value' ('Binding<Double>?' and 'Double') are expected to be equal}}
}
}