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.
Goal
Add
withas the canonical data-variant construction separator.Source rules
Enum::Variant with <value>.Enum::Variant.withon payloadless variants is invalid.withfor data variants is invalid once this syntax is adopted.Enum::Variant(...)remains invalid..Variantconstruction and generic argument inference remain separate work.Compiler scope
withafter fully named variant paths.with.with { field = value }and keep declaration-order field validation..Point{ ... }and.{ ... }.VariantMakelowering.Validation
VariantMakepath is reused.x_testfixtures with bundledbuild/bin/peeper.