-
Notifications
You must be signed in to change notification settings - Fork 425
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
Prevent unrelated casts using as
#2092
Comments
Tracked in Apple’s issue tracker as rdar://114330180 |
What does the term "as well as |
Oh, that was an artifact of a sentence I started writing but then didn’t finish. Ignore it – and I removed it from the description |
If I have a |
I believe we should keep this part of the casting API. If you find a while you could review my pull request #2108, which contains a draft proposal on casting constraints? |
The proposal here is to remove the |
Okay, so a |
Oh, I get it. Sorry, I misunderstood what was being described here. I'll be quiet. :) |
@ahoppen if I remember correctly, we previously discussed having some follow-up PRs related to the main one (#2108). Should we keep closed the current issue and create new ones, or would you prefer to continue using this issue to track all follow-ups? Things to do:
|
Oh, sorry. I shouldn’t have closed this issue just yet. |
Currently,
SyntaxProtocol
has anas
method that allows casting to any other syntax node type. Because of this, it’s possible to e.g. cast aFunctionDeclSyntax
to anIdentifierExprSyntax
without any compiler errors or warnings, even though we know that the cast will always fail.What we should do instead, is to only have a
as(_: ExprSyntaxProtocol.Type)
function onExprSyntax
(analogous forStmtSyntax
and the other base nodes).The
as
function onSyntaxProtocol
can then be marked as deprecated and produce a warning that the cast will always fail.is
andcast
will need to be updated accordingly.The text was updated successfully, but these errors were encountered: