diff --git a/src/variable.jl b/src/variable.jl index 4be29fdc6..aba9ba502 100644 --- a/src/variable.jl +++ b/src/variable.jl @@ -471,11 +471,11 @@ Also see `variables`. """ function variable(name, idx...; T=Real) name_ij = Symbol(name, join(map_subscripts.(idx), "ˏ")) + v = Sym{T}(name_ij) if T <: FnType - first(@variables $name_ij(..)) - else - first(@variables $name_ij::T) + v = CallWithMetadata(v) end + Num(setmetadata(v, VariableSource, (:variables, name_ij))) end ##### Renaming ##### diff --git a/test/macro.jl b/test/macro.jl index bc8ca78ee..5d9f417a0 100644 --- a/test/macro.jl +++ b/test/macro.jl @@ -158,3 +158,15 @@ let @test foo(x) isa Num @test foo(unwrap(x)) isa BasicSymbolic end + +@variables t y(t) +yy = Symbolics.variable(:y, T = Symbolics.FnType{Tuple{Any}, Real}) +yyy = yy(t) +@test isequal(yyy, y) +@test yyy isa Num +@test y isa Num +yy = Symbolics.variable(:y, T = Symbolics.FnType{Tuple, Real}) +yyy = yy(t) +@test !isequal(yyy, y) +@variables y(..) +@test isequal(yyy, y(t))