diff --git a/src/utils.jl b/src/utils.jl index 2167bed06..5fffae8a5 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -233,7 +233,7 @@ end function var_from_nested_derivative(x,i=0) x = unwrap(x) - if issym(x) + if issym(x) || x isa CallWithMetadata (x, i) elseif iscall(x) operation(x) isa Differential ? diff --git a/test/utils.jl b/test/utils.jl index 5121a0300..616dee642 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -1,5 +1,5 @@ using Symbolics -using Symbolics: symbolic_to_float +using Symbolics: symbolic_to_float, var_from_nested_derivative @testset "get_variables" begin @variables t x y z(t) @@ -29,3 +29,12 @@ end @test symbolic_to_float((big(1)//2)*√(279//4)) isa BigFloat @test symbolic_to_float((-1//2)*√(279//4)) isa Float64 end + +@testset "var_from_nested_derivative" begin + @variables t x(t) p(..) + D = Differential(t) + @test var_from_nested_derivative(x) == (x, 0) + @test var_from_nested_derivative(D(x)) == (x, 1) + @test var_from_nested_derivative(p) == (p, 0) + @test var_from_nested_derivative(D(p(x))) == (p(x), 1) +end