Skip to content

Commit e71a55e

Browse files
committed
Print a special message when we fail getting a keypath value
1 parent fc5da53 commit e71a55e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

stdlib/public/core/KeyPath.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,21 @@ public class KeyPath<Root, Value>: PartialKeyPath<Root> {
375375
return _openExistential(valueType, do: project2)
376376
}
377377

378-
if let result = _openExistential(curBase, do: project) {
378+
let result = _openExistential(curBase, do: project)
379+
380+
if let result = result {
379381
return result
380382
}
383+
384+
// Note: This should never be taken. The only time this will occur is if
385+
// the API keypath is referencing has a nullability violation.
386+
// In certain cases, `Value` has the same layout as `Value?` and the
387+
// "nullptr" representation of `Value` is represented as `nil` for
388+
// `Value?`. If we're returning a `Value`, but manage to get its `nil`
389+
// representation, then the above check will fail.
390+
if _slowPath(isLast) {
391+
_preconditionFailure("Could not resolve KeyPath")
392+
}
381393
}
382394
}
383395
}

0 commit comments

Comments
 (0)