Skip to content

Diagnostic: warn on undeclared variables #62

@msarson

Description

@msarson

Summary

Add a diagnostic warning for variables used in a procedure body that cannot be resolved to any declaration in scope.

Motivation

Currently the extension has no way to catch typos or missing declarations at edit time. The compiler catches these, but early feedback in the editor would improve the development experience.

Scope of work

Clarion variable scope is multi-layered — resolution must check in order:

  1. Local procedure variables (declared before \CODE)
  2. Parameters (from the \PROCEDURE()\ signature)
  3. \LOC:-prefixed parameter aliases
  4. Module-level variables (declared before the first procedure)
  5. Global variables (from other \MEMBER\ files)
  6. Class fields (when inside a method implementation)
  7. Queue/Group/File fields (accessible after \SET/loop)
  8. Built-in Clarion identifiers (\RECORDS, \ERRORCODE, \SELF, \PARENT, etc.)

Cross-file resolution is required for globals and class fields, making this expensive and prone to false positives if any layer is incomplete.

Risks / considerations

  • High false-positive risk — any missed declaration source produces spurious red squiggles and erodes trust in all diagnostics
  • \OMIT/\COMPILE\ conditional blocks mean some declarations may be conditionally absent
  • \LIKE, \DIM, embedded group fields, queue fields are all valid declaration sources
  • Should be opt-in / off by default via a setting until coverage is solid
  • \ScopeAnalyzer\ and \SymbolFinderService\ provide a starting point but do not cover all cases

Suggested approach

Start narrow: single-file procedures only, no cross-file dependencies, flag only obvious unresolved identifiers on the left-hand side of assignments. Expand scope incrementally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions