-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SyntaxNodes: DotSelfExpr should have optional base expression. #21926
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
@swift-ci please smoke test |
eabadad
to
9c42e97
Compare
@swift-ci please smoke test and merge |
@@ -532,7 +532,7 @@ struct S : Q, Equatable { | |||
@_implements(P, x) | |||
var y: String | |||
@_implements(P, g()) | |||
func h() {} | |||
func h() { _ = \.self } |
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.
This is a keypath, not a DotSelfExpr. I don't think its correct that DotSelfExpr's base is optional; you should instead parse keypaths differently. CC @jckarter
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.
We parse them as DotSelfExpr too for AST, see here.
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.
I see it parses like this:
(keypath_expr type='<null>'
<<null>>
(dot_self_expr type='<null>'
(key_path_dot_expr implicit type='<null>')))))))
So the base is a KeyPathDotExpr. Do you not have an equivalent in SwiftSyntax? It would be better if the base was never optional here and with MemberExpr also.
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.
Syntax tree doesn't have equivalent implicit nodes in general. All nodes should cover at least one underlying token.
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.
The only exception is collection syntax like CodeBlockItemList
, which can be an empty set of items.
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.
a.self
is creating a DotSelfExpr
syntax node while .self
is creating a ImplicitMemberExpr
one. If we want to be consistent here then shouldn't \.self
be a KeyPathExpr
wrapping an ImplicitMemberExpr
?
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.
Also there is a difference in .a
creating a ImplicitMemberExpr
node while \.a
is a MemberAccessExpr
wrapped by KeyPathExpr
.
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.
a.self
is creating aDotSelfExpr
syntax node while.self
is creating aImplicitMemberExpr
one. If we want to be consistent here then shouldn't\.self
be aKeyPathExpr
wrapping anImplicitMemberExpr
?
After further discussion with Xi, this is explained by the parser treating these differently, .self
being a unresolved_member_expr
while \.self
creating a dot_self_expr
.
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.
Ok, makes sense. Since SwiftSyntax is trying to be more uniform and elegant perhaps it would make sense if .self
in all contexts was a MemberRefExpr with an identifier of self
? Does it make sense for it to be its own thing?
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.
yeah, i think this suggestion makes sense. We could reuse existing MemberAccessExpr
to cover DotSelfExpr
. We could also use MemberAccessExpr
to represent ImplicitMemberExpr
to further reduce the type complexity.
@swift-ci please smoke test |
rdar://46935325