Skip to content

If local const - #366

Merged
Kampfkarren merged 3 commits into
mainfrom
if-local-const
Sep 24, 2026
Merged

Kampfkarren merged 3 commits into
mainfrom
if-local-const

Conversation

@Kampfkarren

Copy link
Copy Markdown
Owner

No description provided.

Kampfkarren and others added 3 commits September 24, 2026 12:32
The `if local` RFC (luau-lang/rfcs#238) allows a `local` or `const`
binding in the condition of an `if`/`elseif` statement or expression,
scoping the variable to the `then`-block:

    if local player = getPlayer() then
        print(player.Name)
    end

Grammar: ('local' | 'const') Name [':' Type] '=' exp, parsed as the
entire condition. `local` is a reserved keyword so `if local` is
unambiguous; `const` uses one token of lookahead (`const` followed by a
name is a binding, otherwise it stays a plain variable).

- New `IfConditionBinding` node holding the local/const token, name,
  optional type specifier, and `=`.
- Optional `binding` field on `If`, `ElseIf`, `IfExpression`, and
  `ElseIfExpression` (cfg-gated behind `luau` for the core structs).
- Unsupported forms fail with clear errors: multi-return bindings and
  compound conditions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Kampfkarren
Kampfkarren merged commit 994a0dd into main Sep 24, 2026
1 of 2 checks passed
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.

1 participant