Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,12 @@ function collectvars(ex::Expr, vars::Vector{Symbol}=Symbol[])
if isa(lhs, Symbol)
push!(vars, lhs)
elseif isa(lhs, Expr) && lhs.head == :tuple
append!(vars, lhs.args)
args = lhs.args
if !isempty(args) && isa(first(args), Expr)

This comment was marked as resolved.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know if this is robust across julia versions? I'd like to see a more selective test, that perhaps checks the head of some of these exprs. to see that they are namedtuples.

e.g. probably we should see :parameters somewhere in here:

julia> dump(:((; x, y) = a))
Expr
  head: Symbol =
  args: Array{Any}((2,))
    1: Expr
      head: Symbol tuple
      args: Array{Any}((1,))
        1: Expr
          head: Symbol parameters
          args: Array{Any}((2,))
            1: Symbol x
            2: Symbol y
    2: Symbol a
    ```

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more selective test, adding an error message in unrecognized cases.
The only cases I can think of that would initially parse but than trigger the error are the invalid forms (; x, y=3) = z and (x, y; z) = q.

# named tuple destructuring
args = first(args).args
end
append!(vars, args)
end
elseif (ex.head == :comprehension || ex.head == :generator)
arg = ex.args[1]
Expand Down
12 changes: 8 additions & 4 deletions test/ExecutionTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,14 @@ tune!(b)
"good")
@test_throws UndefVarError local_var
@benchmark some_var = "whatever" teardown = (@test_throws UndefVarError some_var)
@benchmark foo, bar = "good", "good" setup = (foo = "bad"; bar = "bad") teardown = (@test foo ==
"good" &&
bar ==
"good")
@benchmark foo, bar = "good", "good" setup = (foo = "bad"; bar = "bad") teardown = @test(
foo == "good" && bar == "good"
)
if VERSION >= v"1.7"
@benchmark (; foo, bar) = (foo="good", bar="good") setup = (foo = "bad"; bar = "bad") teardown = @test(
foo == "good" && bar == "good"
)
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are good, but if I understand correctly, I think this is missing the case where we interpolate a value from local scope with dollar, since that's part of the code that this PR changes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added tests for interpolated values both for the tuple and named tuple case (though I don't think the code I changed is specific to interpolation in any way).


# test variable assignment with `@benchmark(args...)` form
@benchmark(
Expand Down