diff --git a/src/arrays.jl b/src/arrays.jl index 3d71a62a3..4946a8ef1 100644 --- a/src/arrays.jl +++ b/src/arrays.jl @@ -727,7 +727,12 @@ function scalarize(arr) end elseif istree(arr) && operation(arr) == getindex args = arguments(arr) - scalarize(args[1], (args[2:end]...,)) + scalarized = scalarize(args[1], (args[2:end]...,)) + if isnothing(metadata(arr)) + scalarized + else + metadata(scalarized, metadata(arr)) + end elseif arr isa Num wrap(scalarize(unwrap(arr))) elseif istree(arr) && symtype(arr) <: Number diff --git a/test/arrays.jl b/test/arrays.jl index 68c8f6ead..99c2039dc 100644 --- a/test/arrays.jl +++ b/test/arrays.jl @@ -161,6 +161,11 @@ getdef(v) = getmetadata(v, Symbolics.VariableDefaultValue) @variables t F(t)[1:1] @test isequal(collect(F ./ t), [F[1] / t]) + + @variables a[1:2] + x = setmetadata(a[1], TestMetaT, 5) + @test getmetadata(x, TestMetaT) == 5 + @test getmetadata(scalarize(x), TestMetaT) == 5 end n = 2