Skip to content

fix: report bare identifier assignment as a compile error#8

Merged
otnc merged 1 commit into
mainfrom
fix/issue-5-bare-assignment-error
Jul 14, 2026
Merged

fix: report bare identifier assignment as a compile error#8
otnc merged 1 commit into
mainfrom
fix/issue-5-bare-assignment-error

Conversation

@otnc

@otnc otnc commented Jul 13, 2026

Copy link
Copy Markdown
Member

Summary

x be value on a bare identifier was parsed permissively and the assignment silently dropped — it compiled to x;, so code ran with stale values and no diagnostics.

Per the RFC (6.4 Assignment), bare identifier assignment is not supported by design (it prevents accidental implicit globals). This PR makes the compiler actually say so instead of silently discarding the code.

Changes

  • parser: new Parser::errors array collects diagnostics; bare identifier assignment pushes a descriptive error:
    Error: bare identifier assignment ('y be ...') is not supported. Declare with 'const y be ...' or 'let y be ...', or use compound assignment such as 'y add be 1'
    
  • cmd: purus build / purus check print collected errors and exit 1
  • pkg: compile() / check() now surface the compiler's output in the thrown Error instead of a generic "Command failed" message

Property (obj.x be), index (arr[\0] be), slice, destructuring ([a; b] be), and compound (x add be 1) assignments are unaffected.

Tests

  • moon test --target js: 320 passed
  • Added parser tests: error recorded for x be 10 and for reassignment after let; no errors for property/index/compound assignments
  • E2E: compile('let y be 10\ny be 20') now throws with the message above; valid code still compiles

Note for docs

The website docs currently contradict the RFC on this point (operators.mdx shows y be 20; control-flow.mdx uses i be i add 1 in while examples — those examples infinite-loop today). They should be updated to use compound assignment; I can follow up with a puruslang/docs PR.

Fixes #5

`x be value` on an already-declared (or undeclared) bare identifier was
parsed permissively and the assignment silently dropped, compiling to a
bare expression statement (`x;`). Code that looked valid ran with stale
values and no diagnostics.

Per the RFC (6.4 Assignment), bare identifier assignment is not
supported by design. This change makes the compiler say so:

- parser: collect diagnostics in a new `Parser::errors` array; bare
  identifier assignment pushes a descriptive error suggesting
  const/let or compound assignment
- cmd: `purus build` / `purus check` print collected errors and exit 1
- pkg: `compile()` / `check()` surface the compiler's stderr/stdout in
  the thrown Error instead of a generic "Command failed" message

Property, index, slice, destructuring, and compound assignments are
unaffected.

Fixes #5
@otnc otnc merged commit 31f7afd into main Jul 14, 2026
1 check passed
@otnc otnc deleted the fix/issue-5-bare-assignment-error branch July 14, 2026 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bare reassignment x be value is silently dropped (compiles to x;)

1 participant