Skip to content

Clean up syntactic multi-assignment? #54748

Open
@Keno

Description

In the lowering source code, we have a comment that says

;; local x, y=2, z => local x;local y;local z;y = 2

but these days, without parentheses that's actually

local (x, y)=(2, z)

i.e. a destructuring assignment to x and y.

However, even with parentheses, I'm not sure the behavior is actually what you want:

julia> global (a::Float64=1), (b::Int64=2.0), c
2.0

This returns the right-most assignment, but that seems like a bit of an arbitrary return value.

I would strongly suggest that we make that syntax case (which is unreachable without parentheses anyway) an error and only permit a single syntactic assignment per statement.

I will also note that the original code that added this behavior wanted it "for consistency with let", but let parses different these days:

julia> let a,b=2
           (a,b)
       end
ERROR: UndefVarError: `a` not defined in local scope
Suggestion: check for an assignment to a local variable that shadows a global of the same name.
Stacktrace:
 [1] top-level scope
   @ REPL[8]:2

julia> let;
           local a,b=2
           (a, b)
       end
ERROR: BoundsError: attempt to access Int64 at index [2]
Stacktrace:
 [1] indexed_iterate(I::Int64, i::Int64, state::Nothing)
   @ Base ./tuple.jl:169
 [2] top-level scope
   @ REPL[12]:2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    compiler:loweringSyntax lowering (compiler front end, 2nd stage)parserLanguage parsing and surface syntax

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions