-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[SR-14096] KeyPath when used as a multi-argument function type #56482
Comments
@swift-ci create |
Sure! Thanks for the ping @xedin =] |
Yeah, in an assert build #2 crashes on assertion |
The problem for the #2 case is that type checker don't detect that for the of key path value (Self) throws -> Bool doesn't match the expected contextual function result type Bool. |
@LucianoPAlmeida I think #2 and #3 should type-check because they are equivalent to:
It seems to be the reason why they don't is because `Self` is misinterpreted. |
Ah that makes sense, but the same behavior also happens if `filterOut` is declared as explicit as`String` var filterOut : (String) throws -> Bool { { $0.contains("a") } } My reasoning in thinking that it could be correct diagnose #2 as a mismatch the same way #3, was that based on key path as functions, #3 `_ = unsorted.filter({ $0[keyPath: \String.filterOut] })` where the result of key path application is a unapplied function type `(String) -> Bool` that indeed doesn't match the expected return type `Bool` |
Ah yes, looks like I misunderstand what SE-0249 was all about - it's supposed to be possible to convert keypath to a function that accepts a base and returns a value of member type referenced by a key path, by that logic `.filterOut` is converted into `(String) -> (Self) throws -> Bool` when used as `filter(.filterOut)`. I agree that both #2 and #3 should produce identical errors. |
Hey @xedin, sorry this is in progress for a while but in fact I haven't be able to really work on it, been in a bit of struggle with other things... but will try to pick this up again this week =] |
@LucianoPAlmeida No worries! Take your time. |
Fixed by #36531 artdivin (JIRA User) Please use next available main branch snapshot to verify and close. |
Attachment: Download
Environment
Swift 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
Xcode 12.4 (12D4e)
Additional Detail from JIRA
md5: 23293c02146f4ec64ff505bd8d184b25
Issue Description:
Hello!
I have found an undefined behaviour when compiler doesn't generate correct error messages, i.e. compilation succeeds if the type is omitted, but when the type is specified the compilation error is generated correctly.
See cases #2 and #3 in the attached screenshot.
I will add textual representation into the description as well:
The text was updated successfully, but these errors were encountered: