Description
World3's MDL footer declares 22:Resource unit,Resource units which makes resource_unit and resource_units aliases of the same canonical unit. The parse-time alias resolution in src/simlin-engine/src/units.rs works correctly (the unit test debug_user_alias_with_underscore_identifiers passes), and the regression test wrld3_resource_unit_alias_should_not_conflict in src/simlin-engine/tests/wrld3_unit_errors.rs also passes after being given a word-boundary filter.
Yet running the CLI on the real model still emits diagnostics that treat the two tokens as distinct units:
error in model 'main': ModelError{unit_mismatch: unit inference [...]: unit_mismatch -- unit checking failed; conflicting constraint:
1 == resource_unit/resource_units}
units error in model 'main' variable 'per_capita_resource_use_multiplier': unit_mismatch -- computed units 'resource_units/person/year' don't match specified units
units error in model 'main' variable 'resource_usage_rate': unit_mismatch -- computed units 'resource_unit/year' don't match specified units
So either (a) the current test's filter is still incomplete and misses diagnostics the CLI surfaces, or (b) the inference path in units_infer.rs is building UnitMap keys from a different source (pre-alias token strings) than the parse path that the unit alias tests exercise. The net effect is that the alias set is only collapsed along some paths.
Why it matters
- Modelers using Vensim-style singular/plural unit aliases (a common idiom) hit spurious unit errors on otherwise valid models.
- Undermines confidence in the unit checker: what should be a verification safety net becomes noise.
- Makes WRLD3-style real-world models unusable with unit checking enabled.
Components affected
src/simlin-engine/src/units.rs (alias resolution)
src/simlin-engine/src/units_infer.rs (inference UnitMap construction)
src/simlin-engine/src/units_check.rs (checking UnitMap comparisons)
src/simlin-engine/tests/wrld3_unit_errors.rs::wrld3_resource_unit_alias_should_not_conflict (test likely needs strengthening to reproduce CLI output)
Possible approaches
- Audit all construction sites of
UnitMap keys and ensure each goes through the same alias-normalization helper used by the parser. A single canonicalization entry point with tests that cover both the infer and check paths.
- Strengthen
wrld3_resource_unit_alias_should_not_conflict to match the CLI's rendered error strings exactly (currently it only greps the Debug representation of individual diagnostics). Running the CLI formatter over the same diagnostics inside the test should reproduce the user-visible failure.
- Add a differential test that parses a unit string via the inference path and the checking path and asserts identical
UnitMap representations for aliased tokens.
Context
Discovered while fixing the delay3 conflation bug in commit 6d48816. The existing alias regression test passes, but the real model's CLI output shows the bug is still present -- strong evidence that the test coverage is incomplete and the root cause is a different code path from the one the test exercises.
Related: #35 (general unit checking tracker).
Description
World3's MDL footer declares
22:Resource unit,Resource unitswhich makesresource_unitandresource_unitsaliases of the same canonical unit. The parse-time alias resolution insrc/simlin-engine/src/units.rsworks correctly (the unit testdebug_user_alias_with_underscore_identifierspasses), and the regression testwrld3_resource_unit_alias_should_not_conflictinsrc/simlin-engine/tests/wrld3_unit_errors.rsalso passes after being given a word-boundary filter.Yet running the CLI on the real model still emits diagnostics that treat the two tokens as distinct units:
So either (a) the current test's filter is still incomplete and misses diagnostics the CLI surfaces, or (b) the inference path in
units_infer.rsis buildingUnitMapkeys from a different source (pre-alias token strings) than the parse path that the unit alias tests exercise. The net effect is that the alias set is only collapsed along some paths.Why it matters
Components affected
src/simlin-engine/src/units.rs(alias resolution)src/simlin-engine/src/units_infer.rs(inference UnitMap construction)src/simlin-engine/src/units_check.rs(checking UnitMap comparisons)src/simlin-engine/tests/wrld3_unit_errors.rs::wrld3_resource_unit_alias_should_not_conflict(test likely needs strengthening to reproduce CLI output)Possible approaches
UnitMapkeys and ensure each goes through the same alias-normalization helper used by the parser. A single canonicalization entry point with tests that cover both the infer and check paths.wrld3_resource_unit_alias_should_not_conflictto match the CLI's rendered error strings exactly (currently it only greps the Debug representation of individual diagnostics). Running the CLI formatter over the same diagnostics inside the test should reproduce the user-visible failure.UnitMaprepresentations for aliased tokens.Context
Discovered while fixing the delay3 conflation bug in commit 6d48816. The existing alias regression test passes, but the real model's CLI output shows the bug is still present -- strong evidence that the test coverage is incomplete and the root cause is a different code path from the one the test exercises.
Related: #35 (general unit checking tracker).