From 2b70992fc89ecd3bc0a63512a9c8bdfdf53aad56 Mon Sep 17 00:00:00 2001 From: Yingbo Ma Date: Wed, 17 Jan 2024 14:07:37 -0500 Subject: [PATCH 1/2] `variable(.., T=FnType)` and `at variables` should be consistent --- src/variable.jl | 6 +++--- test/macro.jl | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) 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..75d4b4d9a 100644 --- a/test/macro.jl +++ b/test/macro.jl @@ -158,3 +158,10 @@ 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(Symbolics.value(t)) +@test isequal(yyy, y) +@test yyy isa Num +@test y isa Num From 5cf5a064d34d4225e9a1f99c8e193709b3019514 Mon Sep 17 00:00:00 2001 From: Yingbo Ma Date: Wed, 17 Jan 2024 14:09:31 -0500 Subject: [PATCH 2/2] Stronger tests --- test/macro.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/macro.jl b/test/macro.jl index 75d4b4d9a..5d9f417a0 100644 --- a/test/macro.jl +++ b/test/macro.jl @@ -161,7 +161,12 @@ end @variables t y(t) yy = Symbolics.variable(:y, T = Symbolics.FnType{Tuple{Any}, Real}) -yyy = yy(Symbolics.value(t)) +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))