Skip to content

[Sema] Do not diagnose contextual type mismatches for malformed key path expressions #33230

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

Conversation

LucianoPAlmeida
Copy link
Contributor

This just skips contextual type diagnostic for malformed key path expressions, because this leads at the very least, extra not good diagnostics. What do you think?

@LucianoPAlmeida LucianoPAlmeida requested review from xedin and hborla July 31, 2020 15:52
@LucianoPAlmeida LucianoPAlmeida force-pushed the key-path-diagnostics-contextual branch from ca33bd4 to d92891f Compare July 31, 2020 18:10
Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's already determined and diagnosed that that key path expression is invalid why not just return Type() while generating constraints for it and avoid running solver for invalid AST?

@LucianoPAlmeida
Copy link
Contributor Author

If it's already determined and diagnosed that that key path expression is invalid why not just return Type() while generating constraints for it and avoid running solver for invalid AST?

Humm, haven't thought about that ... makes sense, let's try that! Thanks, @xedin :)

@LucianoPAlmeida
Copy link
Contributor Author

If it's already determined and diagnosed that that key path expression is invalid why not just return Type() while generating constraints for it and avoid running solver for invalid AST?

Seems like doing this, affects code completion in a way, I'm still looking into this and not familiar with code completion ... but seems like it needs to type check \Root to provide completion

@LucianoPAlmeida LucianoPAlmeida force-pushed the key-path-diagnostics-contextual branch from d92891f to 2913ed0 Compare August 1, 2020 02:37
@LucianoPAlmeida
Copy link
Contributor Author

If it's already determined and diagnosed that that key path expression is invalid why not just return Type() while generating constraints for it and avoid running solver for invalid AST?

@xedin
Seems like it still needs to type check in order to provide code completion in situations like:
https://github.com/apple/swift/blob/e35d2d355f54052c75c98d03a0c038d4f576b9f9/test/IDE/complete_swift_key_path.swift#L47

So should we keep this approach, or maybe run the solver only if it is type checking for code completion using SuppressDiagnostics flag otherwise return Type() in CSGen? Not really sure about this last one ...

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If code completion relies on this behavior then, LGTM! :) Let's name that method {is, has}SingleInvalidComponent though for clarify.

@xedin
Copy link
Contributor

xedin commented Aug 1, 2020

@LucianoPAlmeida before you merge please add one more test case like let _: KeyPath<A, C> = \A to make sure that contextual failure is still recorded.

@LucianoPAlmeida LucianoPAlmeida force-pushed the key-path-diagnostics-contextual branch 4 times, most recently from 58221c9 to 4c21b75 Compare August 1, 2020 13:40
@LucianoPAlmeida
Copy link
Contributor Author

@xedin

@LucianoPAlmeida before you merge please add one more test case like let _: KeyPath<A, C> = \A to make sure that contextual failure is still recorded.

Just added, together with a minor adjustments

@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci please smoke test

@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please smoke test Windows platform

@LucianoPAlmeida LucianoPAlmeida requested a review from xedin August 8, 2020 00:06
@LucianoPAlmeida LucianoPAlmeida force-pushed the key-path-diagnostics-contextual branch from 4c21b75 to d9294e8 Compare August 14, 2020 00:36
Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Naming could use some more though.

@LucianoPAlmeida LucianoPAlmeida force-pushed the key-path-diagnostics-contextual branch from 7e5199f to db41dcf Compare August 14, 2020 21:42
@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please smoke test

@LucianoPAlmeida
Copy link
Contributor Author

@xedin Naming and comments fixed :) Just making sure if there's anything else or we could land this?

@xedin
Copy link
Contributor

xedin commented Aug 16, 2020

:shipit:

@LucianoPAlmeida LucianoPAlmeida merged commit b1eccb5 into swiftlang:master Aug 16, 2020
@LucianoPAlmeida LucianoPAlmeida deleted the key-path-diagnostics-contextual branch August 16, 2020 15:27
meg-gupta added a commit that referenced this pull request Aug 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants