Skip to content

@mtkmodel errors when module qualifier is used to create component #2289

Closed
@baggepinnen

Description

@baggepinnen

The following is fine

using ModelingToolkit
using ModelingToolkitStandardLibrary.Blocks

@mtkmodel TankWithInput begin
    @components begin
        in = Constant(k=308.5)
    end
end

but with the namespace Blocks qualifying the access to Constant, the macro errors

using ModelingToolkit
using ModelingToolkitStandardLibrary.Blocks

@mtkmodel TankWithInput begin
    @components begin
        in = Blocks.Constant(k=308.5)
    end
end
ERROR: MethodError: Cannot `convert` an object of type Expr to an object of type Symbol

Closest candidates are:
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:64
  Symbol(::Any...)
   @ Base strings/basic.jl:229

Stacktrace:
  [1] setindex!(A::Vector{Symbol}, x::Expr, i1::Int64)
    @ Base ./array.jl:969
  [2] _unsafe_copyto!(dest::Vector{Symbol}, doffs::Int64, src::Vector{Any}, soffs::Int64, n::Int64)
    @ Base ./array.jl:250
  [3] unsafe_copyto!
    @ ./array.jl:304 [inlined]
  [4] _copyto_impl!
    @ ./array.jl:327 [inlined]
  [5] copyto!
    @ ./array.jl:314 [inlined]
  [6] copyto!
    @ ./array.jl:339 [inlined]
  [7] copyto_axcheck!
    @ ./abstractarray.jl:1182 [inlined]
  [8] Vector{Symbol}(x::Vector{Any})
    @ Base ./array.jl:621
  [9] convert
    @ ./array.jl:613 [inlined]
 [10] push!(a::Vector{Vector{Symbol}}, item::Vector{Any})
    @ Base ./array.jl:1060
 [11] parse_components!(exprs::Vector{Any}, cs::Vector{Symbol}, dict::Dict{Symbol, Any}, body::Expr, kwargs::Vector{Any})
    @ ModelingToolkit ~/.julia/packages/ModelingToolkit/BsHty/src/systems/model_parsing.jl:284
 [12] parse_model!(exprs::Vector{Any}, comps::Vector{Symbol}, ext::Base.RefValue{Any}, eqs::Vector{Expr}, icon::Base.RefValue{Union{String, URIs.URI}}, vs::Vector{Any}, ps::Vector{Any}, sps::Vector{Any}, dict::Dict{Symbol, Any}, mod::Module, arg::Expr, kwargs::Vector{Any})
    @ ModelingToolkit ~/.julia/packages/ModelingToolkit/BsHty/src/systems/model_parsing.jl:238
 [13] _model_macro(mod::Module, name::Symbol, expr::Expr, isconnector::Bool)
    @ ModelingToolkit ~/.julia/packages/ModelingToolkit/BsHty/src/systems/model_parsing.jl:49
 [14] var"@mtkmodel"(__source__::LineNumberNode, __module__::Module, name::Symbol, body::Any)
    @ ModelingToolkit ~/.julia/packages/ModelingToolkit/BsHty/src/systems/model_parsing.jl:31
 [15] eval
    @ ./boot.jl:370 [inlined]
 [16] eval
    @ ./Base.jl:68 [inlined]
 [17] repleval(m::Module, code::Expr, #unused#::String)
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.52.2/scripts/packages/VSCodeServer/src/repl.jl:229
 [18] (::VSCodeServer.var"#110#112"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.52.2/scripts/packages/VSCodeServer/src/repl.jl:192
 [19] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging ./logging.jl:514
 [20] with_logger
    @ ./logging.jl:626 [inlined]
 [21] (::VSCodeServer.var"#109#111"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.52.2/scripts/packages/VSCodeServer/src/repl.jl:193
 [22] #invokelatest#2
    @ ./essentials.jl:819 [inlined]
 [23] invokelatest(::Any)
    @ Base ./essentials.jl:816
 [24] macro expansion
    @ ~/.vscode/extensions/julialang.language-julia-1.52.2/scripts/packages/VSCodeServer/src/eval.jl:34 [inlined]
 [25] (::VSCodeServer.var"#62#63")()
    @ VSCodeServer ./task.jl:514

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions