From 0cd60e62cb54c4e29a5ff32bca308343c48e14e6 Mon Sep 17 00:00:00 2001 From: Joshua Lampert Date: Fri, 2 Jan 2026 15:29:47 +0100 Subject: [PATCH] fix issue 508 --- src/vector_of_array.jl | 31 +++++++++++++++++++++++++++++- test/downstream/symbol_indexing.jl | 8 ++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index fa65b973..f2ff9aa8 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -616,6 +616,33 @@ end end @inline _has_ragged_end(x, xs...) = _has_ragged_end(x) || _has_ragged_end(xs) +# Helper function to resolve RaggedEnd objects in a tuple of arguments +@inline function _resolve_ragged_end_args(A::AbstractVectorOfArray, args::Tuple) + # Handle empty tuple case + length(args) == 0 && return args + if !_has_ragged_end(args...) + return args + end + # For now, we need to resolve only the last argument if it's RaggedEnd (column selector) + # This handles the common case sol[:x, end] where end gets converted to RaggedEnd(0, lastindex) + if args[end] isa RaggedEnd + resolved_last = _column_indices(A, args[end]) + if length(args) == 1 + return (resolved_last,) + else + return (Base.front(args)..., resolved_last) + end + elseif args[end] isa RaggedRange + resolved_last = _resolve_ragged_index(args[end], A, 1) + if length(args) == 1 + return (resolved_last,) + else + return (Base.front(args)..., resolved_last) + end + end + return args +end + @inline function _ragged_getindex(A::AbstractVectorOfArray, I...) n = ndims(A) # Special-case when user provided one fewer index than ndims(A): last index is column selector. @@ -752,7 +779,9 @@ Base.@propagate_inbounds function Base.getindex(A::AbstractVectorOfArray, _arg, _getindex(A, symtype, _arg, args...) end else - _getindex(A, symtype, elsymtype, _arg, args...) + # Resolve any RaggedEnd objects in args before passing to symbolic indexing + resolved_args = _resolve_ragged_end_args(A, args) + _getindex(A, symtype, elsymtype, _arg, resolved_args...) end end diff --git a/test/downstream/symbol_indexing.jl b/test/downstream/symbol_indexing.jl index 5d11fab0..7299456f 100644 --- a/test/downstream/symbol_indexing.jl +++ b/test/downstream/symbol_indexing.jl @@ -63,6 +63,14 @@ sol_ts = sol(ts) test_tables_interface(sol_ts, [:timestamp, Symbol("x(t)"), Symbol("y(t)")], hcat(ts, Array(sol_ts)')) +# Test issue 508: Cannot call `to_index(::RaggedEnd)` with symbolic indexing and end +@testset "Symbolic indexing with end (issue #508)" begin + @test sol[x, end] isa Number + @test sol[y, end] isa Number + @test sol[x, end] == sol[x][end] + @test sol[y, end] == sol[y][end] +end + # Array variables using LinearAlgebra sts = @variables x(t)[1:3]=[1, 2, 3.0] y(t)=1.0