diff --git a/src/systems/model_parsing.jl b/src/systems/model_parsing.jl index 8426967827..52ef0560d7 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 diff --git a/test/model_parsing.jl b/test/model_parsing.jl index fa036e7350..b1d990d1cf 100644 --- a/test/model_parsing.jl +++ b/test/model_parsing.jl @@ -7,6 +7,30 @@ using Unitful ENV["MTK_ICONS_DIR"] = "$(@__DIR__)/icons" +# Mock module used to test if the `@mtkmodel` macro works with fully-qualified names as well. +module MyMockModule +using ..ModelingToolkit, ..Unitful + +export Pin +@connector Pin begin + v(t), [unit = u"V"] # Potential at the pin [V] + i(t), [connect = Flow, unit = u"A"] # Current flowing into the pin [A] + @icon "pin.png" +end + +@mtkmodel Ground begin + @components begin + g = Pin() + end + @icon read(abspath(ENV["MTK_ICONS_DIR"], "ground.svg"), String) + @equations begin + g.v ~ 0 + end +end +end + +using .MyMockModule + @connector RealInput begin u(t), [input = true, unit = u"V"] end @@ -28,12 +52,6 @@ end @variables t [unit = u"s"] D = Differential(t) -@connector Pin begin - v(t), [unit = u"V"] # Potential at the pin [V] - i(t), [connect = Flow, unit = u"A"] # Current flowing into the pin [A] - @icon "pin.png" -end - @named p = Pin(; v = π) @test getdefault(p.v) == π @test Pin.isconnector == true @@ -57,16 +75,6 @@ end @test OnePort.isconnector == false -@mtkmodel Ground begin - @components begin - g = Pin() - end - @icon read(abspath(ENV["MTK_ICONS_DIR"], "ground.svg"), String) - @equations begin - g.v ~ 0 - end -end - resistor_log = "$(@__DIR__)/logo/resistor.svg" @mtkmodel Resistor begin @extend v, i = oneport = OnePort() @@ -127,7 +135,7 @@ end capacitor = Capacitor(; C = C_val) source = Voltage() constant = Constant(; k = k_val) - ground = Ground() + ground = MyMockModule.Ground() end @equations begin