Skip to content

feat(compiler, std): Implement Phase 1 (defer statements, Option/Result types, try operator ?) - #212

Open
DZTic wants to merge 1 commit into
rux-lang:devfrom
DZTic:feature/phase1-defer-option-result-try
Open

feat(compiler, std): Implement Phase 1 (defer statements, Option/Result types, try operator ?)#212
DZTic wants to merge 1 commit into
rux-lang:devfrom
DZTic:feature/phase1-defer-option-result-try

Conversation

@DZTic

@DZTic DZTic commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

What and Why

This PR implements Phase 1 of language enhancements for Rux to bring ergonomic resource cleanup, standard error types, and error propagation matching high-performance languages like Rust:

  1. defer Statements (defer ; or defer { ... }):

    • Added defer token, AST node (DeferStmt), parsing, and semantic analysis.
    • Implemented deferStack in AstToHirLowering for LIFO automatic scope cleanup at block exit and upon
      eturn.
  2. Standard Option and Result<T, E> Enum Types:

    • Added Option (Some, None) and Result<T, E> (Ok, Err, Success, Error) enums to Packages/Rux/Src/.
  3. Error Propagation Operator ? (expr? / TryExpr):

    • Added postfix ? parsing with intelligent disambiguation for ternary expressions (cond ? then : else).
    • Lowered TryExpr to HIR unary operator.

Verification

sh cmake -S . -B Build -G Ninja -DRUX_BUILD_TESTS=ON cmake --build Build --config Release ./Bin/Tests/Unit/rux-tests.exe ./Bin/rux --manifest Rux.toml check ./Format.ps1

Checklist

  • Branched from dev and targeting dev
  • Release build passes locally
  • [x]
    ux check /
    ux test passes from the repository root
  • [x]
    ux-tests.exe passes (171/171 unit tests)
  • Sources formatted with ./Format.ps1
  • Tests added: Defer, Option, Result, Try test suites under Tests/Language/

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