-
Notifications
You must be signed in to change notification settings - Fork 38
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
Casts can have a side-effect and thus their object can be used #551
base: master
Are you sure you want to change the base?
Casts can have a side-effect and thus their object can be used #551
Conversation
What does this change is meant to achieve, since as far as I understand this visitor class is meant to capture the return value of expression? |
There are methods such as this in the stdlib that use the fact that # Checks that the underlying value is `Nil`, and returns `nil`.
# Raises otherwise.
def as_nil : Nil
@raw.as(Nil)
end |
It seems to me there are some logic faults in here: a) Any object that's being used in a |
What's your reasoning for this? With this, I've found a handful of places in the stdlib where the return type was |
It's pretty common to simply leave the last expression in such methods as is - which is not a mistake, since the |
Last line of def bodies are always considered used (regardless of return type restriction)
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'm still not sure if the casts should increment the stack - i.e. what cases does that cover?
Incrementing the stack before visiting the cast object tells the visitor that the object's return value is used by the cast. It means |
Ok, I guess my confusion stems from the fact that it technically is still unused, yet |
This was my mistake when originally implementing the ImplicitReturnVisitor. |
I probably should've had add that this is only relevant to the expressions with side-effects and not literals and such, sorry for the confusion. |
So if there's a literal or an unused variable access on the last line of a method with a |
@nobodywasishere That's correct. |
No description provided.