Skip to content

error is a reserved word but only ever starts a declaration: make it contextual so error works as a field, binding or parameter name #3131

Closed

Description

@ehartford

Part of #3115. Law 1: the user avoids a name for a reason the compiler can already settle.

The lexer returns TK_KW_ERROR for error everywhere (Lexer.w:201), and §29.11 lists it as reserved. The parser consumes it in two places only: a top-level error Name = ... / error Name from A, B declaration (§10.8, §10.9) and the facade header c facade F error E: (§16.2b.4). In both, error is followed by a type name at a declaration start, a position no expression can occupy (two names side by side is not an expression), so the parser can read it from the text the way it already reads c facade ("two contextual identifiers, so neither c nor facade is taken from user programs") and as §29.11 already treats newaxis and implicit.

error has no meaning as a name, so nothing is shadowed: let error = ..., type Response { status: i32, error: str } and fn fail(error: str) simply work. (The postal-mcp user renamed a Response.error field to message to compile.)

Change: drop "error" from the lexer's keyword table; Parser.w's top-level declaration dispatch and the facade header read identifier error followed by an identifier; the declaration-starter lists (Parser.w ~690/699) and the stray-item diagnostic compare the text. Spec: move error from the §29.11 table to its contextual notes (needs Eric's words; delegated-eligible under D98: lexical, easy to reverse, not safety).

Done when: a fixture uses error as a binding, field and parameter beside an error E = ... declaration; err_ fixtures for the declaration still pass.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions