diff --git a/src/ModelingToolkit.jl b/src/ModelingToolkit.jl index bbaeea1a40..7f934a5769 100644 --- a/src/ModelingToolkit.jl +++ b/src/ModelingToolkit.jl @@ -224,6 +224,34 @@ PrecompileTools.@compile_workload begin @variables x(ModelingToolkit.t_nounits) @named sys = ODESystem([ModelingToolkit.D_nounits(x) ~ -x], ModelingToolkit.t_nounits) prob = ODEProblem(structural_simplify(sys), [x => 30.0], (0, 100), [], jac = true) + @mtkmodel __testmod__ begin + @constants begin + c = 1.0 + end + @structural_parameters begin + structp = false + end + if structp + @variables begin + x(t) = 0.0, [description = "foo", guess = 1.0] + end + else + @variables begin + x(t) = 0.0, [description = "foo w/o structp", guess = 1.0] + end + end + @parameters begin + a = 1.0, [description = "bar"] + if structp + b = 2 * a, [description = "if"] + else + c + end + end + @equations begin + x ~ a + b + end + end end export AbstractTimeDependentSystem, diff --git a/src/systems/model_parsing.jl b/src/systems/model_parsing.jl index 1976e89aa2..4632c1b889 100644 --- a/src/systems/model_parsing.jl +++ b/src/systems/model_parsing.jl @@ -246,8 +246,10 @@ end # The comments indicate the syntax matched by a block; either when parsed directly # when it is called recursively for parsing a part of an expression. # These variable definitions are part of test suite in `test/model_parsing.jl` -function parse_variable_def!(dict, mod, arg, varclass, kwargs, where_types; +Base.@nospecializeinfer function parse_variable_def!( + dict, mod, arg, varclass, kwargs, where_types; def = nothing, type::Type = Real, meta = Dict{DataType, Expr}()) + @nospecialize arg isa LineNumberNode && return MLStyle.@match arg begin # Parses: `a` @@ -1355,7 +1357,9 @@ push_something!(v, x...) = push_something!.(Ref(v), x) define_blocks(branch) = [Expr(branch), Expr(branch), Expr(branch), Expr(branch)] -function parse_top_level_branch(condition, x, y = nothing, branch = :if) +Base.@nospecializeinfer function parse_top_level_branch( + condition, x, y = nothing, branch::Symbol = :if) + @nospecialize blocks::Vector{Union{Expr, Nothing}} = component_blk, equations_blk, parameter_blk, variable_blk = define_blocks(branch) for arg in x