Skip to content

mdl: macro parameter named like a control variable is ignored #552

Open

Description

@bpowers

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_equation
  • src/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 to DT etc.)
  • src/simlin-engine/src/datamodel.rs: Model::new_macro backfills the missing parameter as an unused placeholder input

Activity

  1. added
    engine
    compat
    on Jun 8, 2026
  2. changed the title [-]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[/+] on Oct 12, 2026
  3. added
    bug
    on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcompatengine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions