Skip to content

Commit d270dad

Browse files
authored
Merge pull request #70337 from xedin/rdar-72864716
[CSBindings] Unwrap optionals from contextual function type used as a…
2 parents fa9bf17 + 9cd9619 commit d270dad

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,9 @@ void BindingSet::finalize(
667667
assert(isKnownKeyPathType(bindingTy) || bindingTy->is<FunctionType>());
668668

669669
// Functions don't have capability so we can simply add them.
670-
if (bindingTy->is<FunctionType>())
671-
updatedBindings.insert(binding);
670+
if (auto *fnType = bindingTy->getAs<FunctionType>()) {
671+
updatedBindings.insert(binding.withType(fnType));
672+
}
672673
}
673674

674675
// Note that even though key path literal maybe be invalid it's

test/Constraints/keypath.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,17 @@ func test_invalid_argument_to_keypath_subscript() {
304304
// expected-error@-1 {{cannot use value of type 'A' as a key path subscript index; argument must be a key path}}
305305
}
306306
}
307+
308+
extension Collection {
309+
func prefix<R: RangeExpression>(
310+
_ range: R,
311+
while predicate: ((Element) -> Bool)? = nil
312+
) -> SubSequence where R.Bound == Self.Index {
313+
fatalError()
314+
}
315+
}
316+
317+
// https://github.com/apple/swift/issues/56393
318+
func keypathToFunctionWithOptional() {
319+
_ = Array("").prefix(1...4, while: \.isNumber) // Ok
320+
}

0 commit comments

Comments
 (0)