Julia: `a, b = return ...` yields `ERROR: syntax: ssavalue with no def`

Created on 3 Mar 2019  Â·  6Comments  Â·  Source: JuliaLang/julia

julia> macro hasreturn(n)
           quote
               return $n>1 ? (1, 1) : 1
           end
       end
@hasreturn (macro with 1 method)

julia> a, b = @hasreturn 2
ERROR: syntax: ssavalue with no def

julia> macro noreturn(n)
           quote
               $n>1 ? (1, 1) : 1
           end
       end
@noreturn (macro with 1 method)

julia> a, b = @noreturn 2
(1, 1)

julia> x = @noreturn 1
1
lowering

Most helpful comment

a = return 1 just returns 1, without changing a. So a, b = return 1 likewise should just return 1, without changing either a or b, I'd say.

All 6 comments

The two macros are exactly not the same, see the following CodeInfo for judging:
image
I couldn't quite get your point, can you please be more expressioned about your issue?

As per your problem with a, b = @hasreturn 2, you can workaround that by declaring a function/method, e.g,
fun() = @hasreturn 2
a, b = fun()
cuz, as seen from CodeInfo, all that hasreturn is doing is to return a return statement, which can be assigned to a function/method, and then explicitly set a, b to those values.

image

I suspect that @timholy is suggesting that ERROR: syntax: ssavalue with no def is not a very user friendly error message in the circumstances.

Note that the macro doesn't have any significance here, it's just doing a bad job with the error message:

julia> Meta.@lower a, b = return 1
:($(Expr(:error, "ssavalue with no def")))

I know it's a bit of stiff to comment, but what's the resolution of this issue? What is this issue targeting at? To resolve the ERROR thrown?

a = return 1 just returns 1, without changing a. So a, b = return 1 likewise should just return 1, without changing either a or b, I'd say.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omus picture omus  Â·  3Comments

Keno picture Keno  Â·  3Comments

StefanKarpinski picture StefanKarpinski  Â·  3Comments

m-j-w picture m-j-w  Â·  3Comments

i-apellaniz picture i-apellaniz  Â·  3Comments