local-array-bug.mod 1007 B

12345678910111213141516171819202122232425262728
  1. MODULE local_array_bug;
  2. (* MISDIAGNOSED (2026-10-05). The original report said a local ARRAY
  3. inside a PROCEDURE was miscompiled. The actual cause was the module
  4. *name*: this grammar's scanner did not accept `_` in identifiers
  5. (`ident = letter { letter | digit }`), so `local_array_bug` lexed as
  6. `local` + `_array_bug` and the module body was silently dropped
  7. (empty `main`).
  8. FIXED: `M2.atg`'s ident rule now includes "_"
  9. (`ident = letter { letter | digit | "_" }`), per ISO Modula-2.
  10. Regression: compiler/tests/t_under.mod.
  11. Local arrays themselves compile correctly; e.g. with a camelCase
  12. module name this same program exits 60. See also
  13. tests/t_lower5arr.mod for local arrays of records and open-array
  14. arguments. *)
  15. VAR ExitCode : INTEGER;
  16. PROCEDURE P;
  17. VAR a : ARRAY [0..3] OF INTEGER; i : INTEGER;
  18. BEGIN
  19. i := 0;
  20. WHILE i < 4 DO a[i] := i * 10; INC(i) END;
  21. ExitCode := a[0] + a[1] + a[2] + a[3] (* 0+10+20+30 = 60 *)
  22. END P;
  23. BEGIN P END local_array_bug.