Skip to content

Commit 6d176c2

Browse files
authored
[Nonlinear] fix splatting when collection does not support reverse (#2120)
1 parent ec838ca commit 6d176c2

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Nonlinear/parse.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ function _parse_splat_expression(stack, data, expr, x, parent_index)
8787
"`(x + 1)...`, `[x; y]...` and `g(f(y)...)` are not.",
8888
)
8989
end
90-
for xi in reverse(x.args[1])
91-
push!(stack, (parent_index, xi))
90+
for arg in Iterators.Reverse(x.args[1])
91+
push!(stack, (parent_index, arg))
9292
end
9393
return
9494
end

test/Nonlinear/Nonlinear.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,22 @@ function test_pow_complex_result()
973973
return
974974
end
975975

976+
struct _NoReverse{T} <: AbstractArray{T,1}
977+
data::Vector{T}
978+
end
979+
980+
Base.eachindex(x::_NoReverse) = eachindex(x.data)
981+
Base.getindex(x::_NoReverse, args...) = getindex(x.data, args...)
982+
983+
function test_parse_splat_no_reverse()
984+
model = Nonlinear.Model()
985+
x = MOI.VariableIndex.(1:2)
986+
y = _NoReverse(x)
987+
expr = Nonlinear.parse_expression(model, :(+($y...)))
988+
@test expr == Nonlinear.parse_expression(model, :(+($(x[1]), $(x[2]))))
989+
return
990+
end
991+
976992
end
977993

978994
TestNonlinear.runtests()

0 commit comments

Comments
 (0)