Skip to content

Evaluation order in LHS struct destructuring #44013

Closed
@Keno

Description

@Keno

Consider:

julia> struct Foo
          x
          f
       end

julia> f = Foo(1, 2)
Foo(1, 2)

we have:

julia> (; x, f) = f
2

but

julia> (; f, x) = f
ERROR: type Int64 has no field x
Stacktrace:
 [1] getproperty(x::Int64, f::Symbol)
   @ Base ./Base.jl:38
 [2] top-level scope
   @ REPL[6]:1

Also in the first case, the overall return is the new value of f, but I believe it would be more consistent to return the old value of f. I think the syntax should work in phases, where it collects all the values into ssa values and only then applies the updates.

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviorcompiler:loweringSyntax lowering (compiler front end, 2nd stage)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions