Skip to content

Commit 3603725

Browse files
feat: allow index in AtIndex to be symbolic
1 parent 9240c5c commit 3603725

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/code.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ end
444444

445445
function toexpr(s::SetArray, st)
446446
ex = quote
447-
$([:($(toexpr(s.arr, st))[$(ex isa AtIndex ? ex.i : i)] = $(toexpr(ex, st)))
447+
$([:($(toexpr(s.arr, st))[$(ex isa AtIndex ? toexpr(ex.i, st) : i)] = $(toexpr(ex, st)))
448448
for (i, ex) in enumerate(s.elems)]...)
449449
nothing
450450
end

test/code.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,20 @@ SymbolicUtils.Code.cse_inside_expr(sym, ::typeof(foo), args...) = false
288288
ex3 = letblock.body
289289
@test any(isequal(exfoo), arguments(ex3))
290290
end
291+
292+
@testset "`AtIndex` with symbolic index" begin
293+
@syms a b c::Array
294+
ex = SetArray(false, c, [AtIndex(MakeArray([a, b], Array), [a + b, a - b])])
295+
expr = quote
296+
let a = 1, b = 2, c = zeros(Int, 3, 3)
297+
$(toexpr(ex))
298+
c
299+
end
300+
end
301+
arr = eval(expr)
302+
@test arr[1] == 3
303+
@test arr[2] == -1
304+
for i in 3:length(arr)
305+
@test arr[i] == 0
306+
end
307+
end

0 commit comments

Comments
 (0)