-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Parser: parse var as Call evan if var is declared in call args #4114
Parser: parse var as Call evan if var is declared in call args #4114
Conversation
682dbed
to
bcabb8f
Compare
This change is useful in following case for example: class Foo
class_property foo : String = "hello"
p foo
end Currently this file causes compile error: read before assignment to local variable 'foo'. But, this behavior looks like a bug. |
@@ -3687,10 +3688,12 @@ module Crystal | |||
node | |||
end | |||
|
|||
def preserve_stop_on_do(new_value = false) | |||
def preserve_stop_on_do(new_value = false, call_args? = true) |
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.
Could you use is_call_args
instead? call_args?
as a variable name should be a parse error (at least it's not allowed in Ruby, and in Crystal it looks weird). If we don't change it now we'll have to change it later when we fix the parser for this, but I don't want to encourage this names.
old_stop_on_do = @stop_on_do | ||
@stop_on_do = new_value | ||
@call_args_nest += 1 if call_args? |
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.
Maybe call_args_nest should just be incremented and decremented in the methods parse_call_args
and parse_call_args_space_consumed
? I don't think this is the right place to do it.
Thank you for this! I think this change is OK. It's a breaking change, because if you have code similar to the spec you added: macro debug_init(x)
puts "initializing {{x.var}} to {{x.value}}"
{{x}}
end
debug_init a : Int32 = 0
a it will stop working (now it works). But I don't think that's a good usage for a macro, and in general we use I made a few comments, after that I'll review it again and probably merge this. |
@asterite Thanks for reviewing. I fixed to incr/decr |
@makenowjust Thank you! 💚 |
Fixed #4106