Skip to content

Add with variant construction syntax #99

Description

@itsfuad

Goal

Add with as the canonical data-variant construction separator.

let failed = Result::Failed with "404 not found";
let ok = Result::Ok with {
    value = 42,
};
let pending = Result::Pending;

Source rules

  • Data variants construct as Enum::Variant with <value>.
  • Payloadless variants remain Enum::Variant.
  • with on payloadless variants is invalid.
  • Missing with for data variants is invalid once this syntax is adopted.
  • Variants remain cases of one nominal enum type. They are never types, structs, functions, or callable constructors.
  • Enum::Variant(...) remains invalid.
  • Contextual .Variant construction and generic argument inference remain separate work.

Compiler scope

  • Parse with after fully named variant paths.
  • Support scalar, composite, call, array, parenthesized, and braced payload expressions after with.
  • For named payload schemas, support with { field = value } and keep declaration-order field validation.
  • Preserve current struct literal syntax: .Point{ ... } and .{ ... }.
  • Reuse existing resolved construction evidence and shared VariantMake lowering.
  • Do not add a second constructor path or re-resolve variants after typechecking.
  • Update parser recovery for missing payloads, extra payloads, ambiguous control-header boundaries, and invalid call-style variants.
  • Update language-support and tree-sitter grammar after compiler syntax settles.

Validation

  • Parser and recovery tests for assignments, returns, calls, arrays, nested expressions, and control headers.
  • Typechecker tests for generic/non-generic/imported variants, exact field validation, payloadless rejection, call-style rejection, and variants in type position.
  • HIR, MIR, LLVM tests proving existing VariantMake path is reused.
  • LSP hover/completion/diagnostic tests.
  • Positive and negative x_test fixtures with bundled build/bin/peeper.

Activity

  1. moved this from Todo to In Progress in Peeper Roadmapon Aug 26, 2026
  2. itsfuad commented on Aug 27, 2026

    @itsfuad
    MemberAuthor

    Completed across compiler and editor repositories.

    Delivered:

    • canonical Enum::Variant with <expression> construction
    • payloadless/data-case validation and focused recovery
    • whole-payload and struct-field with match patterns
    • semantic construction evidence reused through HIR/MIR/backend lowering
    • exact struct conversion and nominal ability-boundary regressions required by payload handling
    • tree-sitter grammar/corpus and language-support highlighting updates
    • optional-promotion and nominal LSP CI regressions fixed

    Compiler delivery ends at 7ddfe01 on main. Tree-sitter and language-support changes are also merged and synced to their master branches.

    Validation completed: full Go tests, vet, race tests, bundled compiler build, full x_test, formatter checks, and diff checks.

  3. moved this from In Progress to Done in Peeper Roadmapon Aug 27, 2026
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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions