@@ -237,7 +237,7 @@ function parse_model!(exprs, comps, ext, eqs, icon, vs, ps, sps,
237
237
if mname == Symbol (" @components" )
238
238
parse_components! (exprs, comps, dict, body, kwargs)
239
239
elseif mname == Symbol (" @extend" )
240
- parse_extend! (exprs, ext, dict, body, kwargs)
240
+ parse_extend! (exprs, ext, dict, mod, body, kwargs)
241
241
elseif mname == Symbol (" @variables" )
242
242
parse_variables! (exprs, vs, dict, mod, body, :variables , kwargs)
243
243
elseif mname == Symbol (" @parameters" )
@@ -372,24 +372,35 @@ function extend_args!(a, b, dict, expr, kwargs, varexpr, has_param = false)
372
372
end
373
373
end
374
374
375
- function parse_extend! (exprs, ext, dict, body, kwargs)
375
+ function parse_extend! (exprs, ext, dict, mod, body, kwargs)
376
376
expr = Expr (:block )
377
377
varexpr = Expr (:block )
378
378
push! (exprs, varexpr)
379
379
push! (exprs, expr)
380
380
body = deepcopy (body)
381
381
MLStyle. @match body begin
382
382
Expr (:(= ), a, b) => begin
383
- vars = nothing
384
383
if Meta. isexpr (b, :(= ))
385
384
vars = a
386
385
if ! Meta. isexpr (vars, :tuple )
387
386
error (" `@extend` destructuring only takes an tuple as LHS. Got $body " )
388
387
end
389
388
a, b = b. args
390
- extend_args! (a, b, dict, expr, kwargs, varexpr)
391
- vars, a, b
389
+ else
390
+ if (model = getproperty (mod, b. args[1 ])) isa Model
391
+ _vars = keys (get (model. structure, :variables , Dict ()))
392
+ _vars = union (_vars, keys (get (model. structure, :parameters , Dict ())))
393
+ _vars = union (_vars,
394
+ map (first, get (model. structure, :components , Vector{Symbol}[])))
395
+ vars = Expr (:tuple )
396
+ append! (vars. args, collect (_vars))
397
+ else
398
+ error (" Cannot infer the exact `Model` that `@extend $(body) ` refers." *
399
+ " Please specify the names that it brings into scope by:" *
400
+ " `@extend a, b = oneport = OnePort()`." )
401
+ end
392
402
end
403
+ extend_args! (a, b, dict, expr, kwargs, varexpr)
393
404
ext[] = a
394
405
push! (b. args, Expr (:kw , :name , Meta. quot (a)))
395
406
push! (expr. args, :($ a = $ b))
0 commit comments