Skip to content

Commit 53f32e2

Browse files
fix: @mtkmodel no longer makes @variables callable
1 parent 0648e5c commit 53f32e2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/systems/model_parsing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ function generate_var!(dict, a, b, varclass, mod;
497497
vd isa Vector && (vd = first(vd))
498498
vd[a] = Dict{Symbol, Any}()
499499
var = if indices === nothing
500-
Symbolics.variable(a, T = SymbolicUtils.FnType{Tuple{Any}, type})(iv)
500+
first(@variables $a(iv)::type)
501501
else
502502
vd[a][:size] = Tuple(lastindex.(indices))
503503
first(@variables $a(iv)[indices...]::type)

test/model_parsing.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ModelingToolkit, Test
1+
using ModelingToolkit, Symbolics, Test
22
using ModelingToolkit: get_connector_type, get_defaults, get_gui_metadata,
33
get_systems, get_ps, getdefault, getname, readable_code,
44
scalarize, symtype, VariableDescription, RegularConnector,
@@ -990,3 +990,22 @@ struct CustomStruct end
990990
@named sys = MyModel(p = CustomStruct())
991991
@test ModelingToolkit.defaults(sys)[@nonamespace sys.p] == CustomStruct()
992992
end
993+
994+
@testset "Variables are not callable symbolics" begin
995+
@mtkmodel Example begin
996+
@variables begin
997+
x(t)
998+
y(t)
999+
end
1000+
@equations begin
1001+
x ~ y
1002+
end
1003+
end
1004+
@named ex = Example()
1005+
vars = Symbolics.get_variables(only(equations(ex)))
1006+
@test length(vars) == 2
1007+
for u in Symbolics.unwrap.(unknowns(ex))
1008+
@test !Symbolics.hasmetadata(u, Symbolics.CallWithParent)
1009+
@test any(isequal(u), vars)
1010+
end
1011+
end

0 commit comments

Comments
 (0)