Repository navigation
Description
A variable with the same name as a dimension (variable other, dimension Other) is accepted where it is defined.
XMILE forbids this, and the engine assumes it never happens, so each place that meets the name resolves it its own way: one gives a silently wrong number, others give unrelated errors.
The model should be refused at the definition with one clear error.
Example
Dimension Other = {a, b}, other[Other] = 1:
| equation | result |
|---|---|
y[Other] = other |
runs, y = [1, 2]: the element positions of Other, not the variable's [1, 1] |
y[Other] = other[Other] |
runs, y = [1, 1] |
y[Other] = PREVIOUS(other) |
does_not_exist |
y[Other] = PREVIOUS(other[Other]), INIT(other[Other]) |
not_simulatable: "PREVIOUS requires a variable reference after helper rewriting" (INIT similar) |
With a scalar other = 1, y = other fails with "Dimension 'other' cannot be used in a scalar equation".
These were measured on the #1040 branch; the error wording may have changed since, but nothing in main checks the collision.
None of these errors says that other is both a variable and a dimension.
Why it matters
The first row is a silently wrong number.
Seen only in constructed models: a crude scan of the XMILE and MDL files under test/ found no variable sharing a name with a dimension, so refusing should break nothing we know of.
Fix
XMILE 1.0 section 3.7.1: dimension names "must be distinct from model variables names within the whole-model".
Add a check beside the duplicate-variable check (model_duplicate_variables) that reports an error on each variable whose canonical name equals a canonical dimension name, naming the dimension, and refuse the model the way duplicate variables are refused.
The dimension-first lookups elsewhere (the comment in Expr2::from already states the assumption) then hold by construction.
One test with an arrayed and a scalar collision is enough.
Pointers
src/simlin-engine/src/db/diagnostic.rs:model_duplicate_variables,emit_duplicate_variable_diagnosticssrc/simlin-engine/src/ast/expr2.rs:Expr2::from, the comment that assumes the rule
Activity
engine: one ordinal fallback for undeclared dimension pairs
[-]engine: variable-vs-dimension name collision is never refused at definition; each spelling resolves it differently (plain read accepted, PREVIOUS/INIT refused, bare read silently yields the element index)[/-][+]engine: a variable named like a dimension is accepted, then misread[/+]