Hi, I want to be able to identify whether a line of code will return,
because I want to modify it to capture it’s return value. If it returns,
this results in a syntax error:
$ echo ‘def m() a = return end’ | ruby -c
-:1: void value expression
$ echo $?
1
Here are some tests:
Here is what I tried (hooking into on_kw "return" callback in Ripper):
$ echo ‘-> { a = (1 && return) }’ | ruby -c
Syntax OK
I agree, it’s pretty weird. I would guess the “void value expression”
error is actually the parser complaining that the left hand operand of
(({&&}}) is void. The right hand side is allowed to be void so we can
do
things like (({foo.bad? && asplode})). Odd that it doesn’t mind the
right
hand side of the assignment operator being void; I guess the parser
can’t
determine, and by the time it’s evaluated at runtime, the (({return}))
has
already executed, so the point is moot.
By the way, if you do manage to solve the halting problem, please let us
all know.
Hi, I want to be able to identify whether a line of code will return,
because I want to modify it to capture it’s return value. If it returns,
this results in a syntax error:
Why do you need to modify the line? Can’t you catch it at the calling
site or by decorating the method?
I don’t need to record the return statement, though, that seems too
difficult to me. I just need to identify that it will blow up when
executed
so that I don’t try to record it.
Hi, I want to be able to identify whether a line of code will return,
because I want to modify it to capture it’s return value. If it returns,
this results in a syntax error:
Why do you need to modify the line? Can’t you catch it at the calling
site or by decorating the method?
Kind regards
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.