-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[Typechecker] Diagnose key paths with contextual root type but no leading dot #30164
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Actually, I missed one other scenario - the root starting with a resolved but implicit func foo<T>(_: KeyPath<SR_12290, T>) {}
foo(\property.count) At the moment, we already diagnose this with "invalid component of Swift key path", but I have added an explicit check for it so we can emit a better diagnostic now. |
Great, thank you! |
@swift-ci please smoke test |
Once test passes, I'll run source compatibility tests just in case someone is relying on it... if so we might have to downgrade it to a warning. |
That would be really unfortunate... |
@swift-ci please smoke test |
@swift-ci please smoke test Linux platform |
@swift-ci please test source compatibility |
This broke struct Foo: KeyPathIterable {
var float: Float
var int: Float
var string: String
} $ swift kpi.swift
<unknown>:0: error: a Swift key path with contextual root must begin with a leading dot
<unknown>:0: error: a Swift key path with contextual root must begin with a leading dot
<unknown>:0: error: a Swift key path with contextual root must begin with a leading dot Attempting to make the
I wonder what's the best way to address this issue? On Context: we've been incubating |
…leading dot (#30164)" This reverts commit 13487ed. Rationale: #30164 (comment)
Sorry about that @dan-zheng. I think one solutions we discussed on the SR was for the parser to record the missing dot on the AST and use that information in Sema to diagnose. I think that would be the way to go. |
If a Swift key path has root type inferred but does not have a leading dot, then diagnose it, because it's not valid. For example:
The key path's path starts with an implicit
TypeExpr
/DeclRefExpr
as root, which only happens if the type is supposed to be inferred and the leading dot is missing. In all other scenarios, we have either an implicitKeyPathDotExpr
or an explicitTypeExpr
. So, I use this information to detect this scenario and diagnose.Resolves SR-12290
Resolves rdar://problem/59874355