Repository navigation
Description
Inside a Vensim macro body, a parameter named like a control variable (time step, final time, initial time, saveper) is read as the model's control variable, not as the parameter.
The macro ignores what the caller passes for that parameter, with no error.
Example
From the metasd beer game, test/metasd/beer-game/RealBeer4-Sterman13.mdl:
:MACRO: PINK NOISE(noise mean, std deviation, correlation time, time step, seed)
...
scaled white noise = noise mean + white noise*std deviation
*SQRT((2-time step/correlation time)/(time step/correlation time))
Expected: time step in the body is the fourth argument.
Actual (from reading the code, not run): the importer marks the parameter's placeholder as a control variable and drops it, and formats the body reference as DT, the model's time step.
This model passes TIME STEP as the argument, so its numbers happen to come out right; a call passing anything else would be silently wrong.
Why it matters
Seen in a real model, though it does not change that model's results.
Wrong numbers with no diagnostic is the failure mode we least want.
Fix
A macro body has no sim specs, so its conversion should not treat any name as a control variable.
In the macro sub-context, skip the "control variables are not variables" marking in mark_variable_types, and do not rewrite a reference to DT/STOPTIME/... when it names a parameter.
The body's own references to the model's controls are already written TIME STEP$ etc. and handled separately.
Pointers
src/simlin-engine/src/mdl/convert/macros.rs:build_macro_body_variables,synthetic_param_equationsrc/simlin-engine/src/mdl/convert/stocks.rs:mark_variable_types(control variables marked unwanted)src/simlin-engine/src/mdl/xmile_compat.rs:format_name(control-name rewrite toDTetc.)src/simlin-engine/src/datamodel.rs:Model::new_macrobackfills the missing parameter as an unused placeholder input
Activity
[-]engine: Vensim macro formal parameter named like a control variable (Final Time, etc.) is silently dropped on MDL import[/-][+]mdl: macro parameter named like a control variable is ignored[/+]