Skip to content

[CSBindings] Don't favor unresolved key path type over a conjunction #70175

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 4, 2023
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
8 changes: 8 additions & 0 deletions lib/Sema/CSBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,14 @@ bool BindingSet::favoredOverConjunction(Constraint *conjunction) const {
}
}

// If key path capability is not yet determined it cannot be favored
// over a conjunction because:
// 1. There could be no other bindings and that would mean that
// key path would be selected even though it's not yet ready.
// 2. A conjunction could be the source of type context for the key path.
if (TypeVar->getImpl().isKeyPathType() && isDelayed())
return false;

return true;
}

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

// rdar://119055010 - greedy key path type assignment breaks keypath-to-function conversion

protocol Executable {}

final class Wrapper<Value> {
func update<Return>(_ work: (inout Value) throws -> Return) rethrows -> Return {
fatalError()
}
}

enum Lookup<Value> {
func flatMap<T>(_ transform: (Value) throws -> Lookup<T>) rethrows -> Lookup<T> { fatalError() }
}

protocol Entry {
}

extension Entry {
var executable: Lookup<any Executable> {
fatalError()
}
}

func lookup() -> Lookup<any Entry> {
fatalError()
}

struct Test {
struct Data {
}

let value = Wrapper<Data>()

func run() -> Lookup<any Executable> {
value.update { data in
let _ = 42
return lookup()
}
.flatMap(\.executable)
}
}