From 973c09ae663b5045fb54c997fd3e3d09bd2c431f Mon Sep 17 00:00:00 2001 From: Anant Thazhemadam Date: Thu, 7 Dec 2023 23:30:51 +0530 Subject: [PATCH] feat: support components with fully-qualified names with `@mtkmodel` With the `@named` macro, we could use fully-qualified names for components. However, trying to do the same with `@mtkmodel`, ``` @mtkmodel Model begin @components begin resistor = ModelingToolkitStandardLibrary.Electrical.Resistor(R = 1) ... end ... end ``` throws the following error. ``` ERROR: LoadError: 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:84 Symbol(::Any...) @ Base strings/basic.jl:229 ``` Fix this and support fully qualified names by considering the fully-qualifed name's Expr while parsing components. --- src/systems/model_parsing.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/systems/model_parsing.jl b/src/systems/model_parsing.jl index 8426967827..9c7bbeae7e 100644 --- a/src/systems/model_parsing.jl +++ b/src/systems/model_parsing.jl @@ -673,7 +673,7 @@ function _parse_components!(exprs, body, kwargs) expr = Expr(:block) varexpr = Expr(:block) # push!(exprs, varexpr) - comps = Vector{Symbol}[] + comps = Vector{Union{Symbol, Expr}}[] comp_names = [] for arg in body.args @@ -692,7 +692,9 @@ function _parse_components!(exprs, body, kwargs) arg.args[2] = b push!(expr.args, arg) push!(comp_names, a) - push!(comps, [a, b.args[1]]) + if(isa(b.args[1], Symbol) || Meta.isexpr(b.args[1], :.)) + push!(comps, [a, b.args[1]]) + end end _ => error("Couldn't parse the component body: $arg") end