Skip to content

Commit

Permalink
fix: @mtkmodel no longer makes @variables callable
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Nov 22, 2024
1 parent ac39aab commit 39d515a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/systems/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ function generate_var!(dict, a, b, varclass, mod;
vd isa Vector && (vd = first(vd))
vd[a] = Dict{Symbol, Any}()
var = if indices === nothing
Symbolics.variable(a, T = SymbolicUtils.FnType{Tuple{Any}, type})(iv)
first(@variables $a(iv)::type)
else
vd[a][:size] = Tuple(lastindex.(indices))
first(@variables $a(iv)[indices...]::type)
Expand Down
21 changes: 20 additions & 1 deletion test/model_parsing.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ModelingToolkit, Test
using ModelingToolkit, Symbolics, Test
using ModelingToolkit: get_connector_type, get_defaults, get_gui_metadata,
get_systems, get_ps, getdefault, getname, readable_code,
scalarize, symtype, VariableDescription, RegularConnector,
Expand Down Expand Up @@ -979,3 +979,22 @@ end
@test MultipleExtend.structure[:extend][1] == [:inmodel, :b, :inmodel_b]
@test tosymbol.(parameters(multiple_extend)) == [:b, :inmodel_b₊p, :inmodel₊p]
end

@testset "Variables are not callable symbolics" begin
@mtkmodel Example begin
@variables begin
x(t)
y(t)
end
@equations begin
x ~ y
end
end
@named ex = Example()
vars = Symbolics.get_variables(only(equations(ex)))
@test length(vars) == 2
for u in Symbolics.unwrap.(unknowns(ex))
@test !Symbolics.hasmetadata(u, Symbolics.CallWithParent)
@test any(isequal(u), vars)
end
end

0 comments on commit 39d515a

Please sign in to comment.