From d19dc1b8d62f40a19a091cb91e4c4564d14e6eae Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Mon, 18 Nov 2024 16:28:03 +0530 Subject: [PATCH] fix: `@mtkmodel` no longer makes `@variables` callable --- src/systems/model_parsing.jl | 2 +- test/model_parsing.jl | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/systems/model_parsing.jl b/src/systems/model_parsing.jl index 5b79eaa91b..d6cb47146b 100644 --- a/src/systems/model_parsing.jl +++ b/src/systems/model_parsing.jl @@ -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) diff --git a/test/model_parsing.jl b/test/model_parsing.jl index fd223800e3..46bf117bc2 100644 --- a/test/model_parsing.jl +++ b/test/model_parsing.jl @@ -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, @@ -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