Skip to content

Commit 39d515a

Browse files
fix: @mtkmodel no longer makes @variables callable
1 parent ac39aab commit 39d515a

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,
@@ -979,3 +979,22 @@ end
979979
@test MultipleExtend.structure[:extend][1] == [:inmodel, :b, :inmodel_b]
980980
@test tosymbol.(parameters(multiple_extend)) == [:b, :inmodel_b₊p, :inmodel₊p]
981981
end
982+
983+
@testset "Variables are not callable symbolics" begin
984+
@mtkmodel Example begin
985+
@variables begin
986+
x(t)
987+
y(t)
988+
end
989+
@equations begin
990+
x ~ y
991+
end
992+
end
993+
@named ex = Example()
994+
vars = Symbolics.get_variables(only(equations(ex)))
995+
@test length(vars) == 2
996+
for u in Symbolics.unwrap.(unknowns(ex))
997+
@test !Symbolics.hasmetadata(u, Symbolics.CallWithParent)
998+
@test any(isequal(u), vars)
999+
end
1000+
end

0 commit comments

Comments
 (0)