Skip to content
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

a, b = return ... yields ERROR: syntax: ssavalue with no def #31238

Closed
timholy opened this issue Mar 3, 2019 · 6 comments · Fixed by #35399
Closed

a, b = return ... yields ERROR: syntax: ssavalue with no def #31238

timholy opened this issue Mar 3, 2019 · 6 comments · Fixed by #35399
Assignees
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage)

Comments

@timholy
Copy link
Member

timholy commented Mar 3, 2019

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
@eulerkochy
Copy link
Contributor

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?

@eulerkochy
Copy link
Contributor

eulerkochy commented Mar 3, 2019

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

@elextr
Copy link

elextr commented Mar 4, 2019

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

@vtjnash
Copy link
Member

vtjnash commented Mar 4, 2019

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")))

@JeffBezanson JeffBezanson added the compiler:lowering Syntax lowering (compiler front end, 2nd stage) label Mar 4, 2019
@JeffBezanson JeffBezanson changed the title Macro with explicit return yields ERROR: syntax: ssavalue with no def a, b = return ... yields ERROR: syntax: ssavalue with no def Mar 4, 2019
@eulerkochy
Copy link
Contributor

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?

@martinholters
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants