-
Notifications
You must be signed in to change notification settings - Fork 439
Add casting methods to protocols #169
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
e7bac89
to
b58ae97
Compare
@swift-ci Please test |
…ocol This allows us to use SyntaxProtocol as a return value again and provide nice functions that check if type-erased note conforms to a protocol.
swiftlang/swift-stress-tester#109 @swift-ci Please test |
@@ -13,7 +13,7 @@ | |||
/// A Syntax node represents a tree of nodes with tokens at the leaves. | |||
/// Each node has accessors for its known children, and allows efficient | |||
/// iteration over the children through its `children` property. | |||
public struct Syntax: SyntaxProtocol { | |||
public struct Syntax: SyntaxProtocol, SyntaxHashable { |
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.
It's not clear to me, why is SyntaxHashable
a separate protocol than SyntaxProtocol
? Is there something that needs to conform to SyntaxProtocol
but not SyntaxHashable
or vice-versa?
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.
Hashable has a Self
requirement and if we make SyntaxProtocol
conform to Hashable
, we cannot use it as a return type anymore.
These return the non type-erased types of a node if it conforms to the given protocol and nil otherwise. With these methods returning the non type-erased type we can get rid of _asConcreteType.
Damn, had the wrong version of the swift repo checked out and generated outdated swiftlang/swift-stress-tester#109 |
Build failed |
Discard newlines when sorting imports.
These return the non type-erased types of a node if it conforms to the given protocol and
nil
otherwise.With these methods returning the non type-erased type we can get rid of
_asConcreteType
. The new way to get the concrete type of aSyntax
node is to callas(SyntaxProtocol.self)
which will return a non-type-erased type that conforms toSyntaxProtocol
.