Skip to content

diagram: unit inference errors underlined in the wrong place (UnitError kind collapsed to a boolean) #836

Description

@bpowers

Problem

The diagram's per-field unit-error underline misattributes unit inference errors to the units field.

UnitError in src/core/datamodel.ts carries only a boolean isConsistencyError, collapsing the engine's three-valued unit-error kind (Definition | Consistency | Inference -- see SimlinUnitErrorKind in src/engine/src/internal/types.ts). convertErrorDetails in src/diagram/project-controller.ts sets isConsistencyError = (unitErrorKind === Consistency), so an Inference error is treated exactly like a Definition error downstream.

But an inference error's start/end offsets point into the equation, not the units string (see format_unit_error's InferenceError arm in src/simlin-engine/src/errors.rs). highlightRangeForField in src/diagram/equation-highlight.ts applies those equation-relative offsets to the units string, producing a red underline over the wrong span of the units box.

Why it matters

User-facing diagnostic correctness: the red underline points at an arbitrary, wrong span of the units declaration, misleading users about where the problem is. Low severity (display-only), but it undermines trust in the per-field error affordance.

Components affected

  • src/core/datamodel.ts (UnitError.isConsistencyError)
  • src/diagram/project-controller.ts (convertErrorDetails)
  • src/diagram/equation-highlight.ts (highlightRangeForField)

Possible approach

Replace the boolean with kind: 'definition' | 'consistency' | 'inference' on core's UnitError, and give inference errors their own placement rule -- probably a warning underline in the equation field (like consistency errors), or highlighting the whole units declaration.

Context

Pre-existing bug discovered in July 2026 while fixing unit-error display; the consistency and definition paths are now placed correctly -- only inference is mislocated. Related but distinct from #835 (ErrorCode enum numbering skew in the same conversion path).

Activity

  1. added a commit that references this issue on Jul 5, 2026
    f6bc72c
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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions