mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Typed throws] Handle key-path literal used with a function that has typed throws
When providing a key-path literal for a parameter of function type where that function type has a generic parameter for its thrown error type, infer `Never` for the generic argument because key paths don't throw. Thanks to @xedin for realizing that this would be an issue.
This commit is contained in:
@@ -12248,6 +12248,16 @@ ConstraintSystem::simplifyKeyPathConstraint(
|
||||
// { root in root[keyPath: kp] }.
|
||||
boundRoot = fnTy->getParams()[0].getParameterType();
|
||||
boundValue = fnTy->getResult();
|
||||
|
||||
// Key paths never throw, so if the function has a thrown error type
|
||||
// that is a type variable, infer it to be Never.
|
||||
if (auto thrownError = fnTy->getThrownError()) {
|
||||
if (thrownError->isTypeVariableOrMember()) {
|
||||
(void)matchTypes(
|
||||
thrownError, getASTContext().getNeverType(),
|
||||
ConstraintKind::Equal, TMF_GenerateConstraints, locator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (boundRoot &&
|
||||
|
||||
Reference in New Issue
Block a user