Skip to content

Commit

Permalink
[SparseArrayDOKs] Fix escaping in @maybe_grow (#1442)
Browse files Browse the repository at this point in the history
  • Loading branch information
emstoudenmire authored May 14, 2024
1 parent 3b86785 commit 12e45d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion NDTensors/src/lib/SparseArrayDOKs/src/sparsearraydok.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,5 @@ macro maybe_grow(expr)
)
end
@capture(expr, array_[indices__] = value_)
return :(setindex_maybe_grow!($(esc(array)), $value, $indices...))
return :(setindex_maybe_grow!($(esc(array)), $(esc(value)), $(esc.(indices)...)))
end
9 changes: 9 additions & 0 deletions NDTensors/src/lib/SparseArrayDOKs/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ using SparseArrays: SparseMatrixCSC, nnz
@maybe_grow v[5] = 50
@test size(v) == (5,)
@test v[5] == 50
# Test setting from a variable (to test macro escaping)
i = 6
val = 60
@maybe_grow v[i] = val
@test v[i] == val
i, j = 1, 2
val = 120
@maybe_grow a[i, j] = val
@test a[i, j] == val
end
@testset "Test Lower Level Constructor" begin
d = Dictionary{CartesianIndex{2},elt}()
Expand Down

0 comments on commit 12e45d0

Please sign in to comment.