Skip to content

engine: a bad unit declaration is reported against a nameless model #456

Open

Description

@bpowers

An error in a project-level unit declaration is printed as if it belonged to a variable in a model with an empty name.
It should say it is about the project's unit list and name the unit.

Example

cargo run -p simlin-cli -- simulate --ltm test/conveyors/covid19_severity.stmx

prints, among others:

units error in model '' variable 'euros_per_year_per_person': bad_binary_op_in_units
units error in model '' variable 'dollars_per_month_per_worker': bad_binary_op_in_units

euros_per_year_per_person is a unit, not a variable.
Its declaration is EUR/(person-year); the unit parser reads - as subtraction.
That file was saved by Stella, so the hyphen may be Stella's way of writing a product (unverified).

Model-level errors with no model already print as error in the project: ...; unit declaration errors take the per-variable branch instead.

This issue was first filed for World3's duplicate_unit errors, repeated once per SMOOTH/DELAY call.
Those no longer occur: repeated identical 22: unit lines are tolerated, and project-level unit errors are emitted once rather than once per model.

Why it matters

The message points a modeler at a variable that does not exist.
Seen on covid19_severity.stmx, a real Stella model.

Fix

Give unit-definition errors filed under no model their own summary line, e.g. units error in the project, unit 'euros_per_year_per_person': ..., mirroring the existing project-level branch.
Separately, check whether Stella's unit syntax uses - for multiplication; if it does, accept it in the unit parser.

Pointers

  • src/simlin-engine/src/errors.rs (format_diagnostic_inner, the DiagnosticError::Model(_) if model.is_empty() arm)
  • src/simlin-engine/src/db/diagnostic.rs (collect_all_diagnostics, where unit definition errors are emitted)
  • src/simlin-engine/src/units.rs (unit equation parser, BadBinaryOpInUnits)

Activity

  1. added
    engine
    on Jun 8, 2026
  2. bpowers commented on Jul 11, 2026

    @bpowers
    OwnerAuthor

    Additional evidence: this is not specific to duplicate_unit. The same empty-model + N-fold duplication reproduces with bad_binary_op_in_units on a different fixture:

    cargo run -p simlin-cli -- simulate --ltm test/conveyors/covid19_severity.stmx 2>&1 | grep bad_binary_op_in_units
    

    emits each of these 10 times:

    units error in model '' variable 'euros_per_year_per_person': bad_binary_op_in_units
    units error in model '' variable 'dollars_per_month_per_worker': bad_binary_op_in_units
    units error in model '' variable 'jobs_per_month_per_worker': bad_binary_op_in_units
    

    The original report guessed at db.rs/stdlib.gen.rs. The actual emission site is src/simlin-engine/src/db/query.rs:62-74, in the salsa-tracked project_units_context:

    • model: String::new() is hardcoded, which is where the in model '' comes from.
    • variable: Some(unit_name.clone()) puts a unit definition name into the variable slot. euros_per_year_per_person et al. are project-level unit aliases, not model variables -- so a project-level unit-definition error is being reported through the per-variable diagnostic channel. That confirms the "not model-scoped" hypothesis in the original description, and explains why no UI can navigate to it.
    • The duplication is the accumulator drain: project_units_context accumulates CompilationDiagnostic once, but collect_all_diagnostics drains per model, so a project with N models/module instances re-reports every project-level unit diagnostic N times. The count tracks models/instances, matching the ~20x observed on World3 and the 10x here.

    So both halves of this issue live in one place, and the fix has to give project-scoped diagnostics a channel of their own (or at minimum an attribution field distinct from (model, variable)) plus a single drain. Approach 1 in the description still looks right for the duplicate_unit half, but it will not by itself fix bad_binary_op_in_units, which is a genuine syntax error in a user unit declaration and must still be reported -- exactly once, attributed to the declaration rather than to a nonexistent model variable.

    Discovered while fixing #919 (which only touches the severity word and the Error-severity gating of has_model_errors/has_variable_errors; the attribution and dedup bug here is orthogonal and untouched by that PR).

  3. added
    bug
    on Oct 12, 2026
  4. changed the title [-]engine: duplicate_unit diagnostics emitted once per stdlib module instance[/-] [+]engine: a bad unit declaration is reported against a nameless model[/+] 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

    bugengine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions