Skip to content

Commit 12e45d0

Browse files
[SparseArrayDOKs] Fix escaping in @maybe_grow (#1442)
1 parent 3b86785 commit 12e45d0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

NDTensors/src/lib/SparseArrayDOKs/src/sparsearraydok.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,5 @@ macro maybe_grow(expr)
144144
)
145145
end
146146
@capture(expr, array_[indices__] = value_)
147-
return :(setindex_maybe_grow!($(esc(array)), $value, $indices...))
147+
return :(setindex_maybe_grow!($(esc(array)), $(esc(value)), $(esc.(indices)...)))
148148
end

NDTensors/src/lib/SparseArrayDOKs/test/runtests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ using SparseArrays: SparseMatrixCSC, nnz
119119
@maybe_grow v[5] = 50
120120
@test size(v) == (5,)
121121
@test v[5] == 50
122+
# Test setting from a variable (to test macro escaping)
123+
i = 6
124+
val = 60
125+
@maybe_grow v[i] = val
126+
@test v[i] == val
127+
i, j = 1, 2
128+
val = 120
129+
@maybe_grow a[i, j] = val
130+
@test a[i, j] == val
122131
end
123132
@testset "Test Lower Level Constructor" begin
124133
d = Dictionary{CartesianIndex{2},elt}()

0 commit comments

Comments
 (0)