Files
sx/examples/162-pack-bare-args.sx
agra 8a875d354c lang F1 2.7: pack-as-value diagnostics (Phase 2 complete)
Using a bare pack name where a runtime value is required was silent garbage
(f(xs)/return xs produced a stray pointer). Now a clear, context-tailored
compile error: isPackName + diagPackAsValue, caught at lowerVarDecl (storage),
lowerReturn (return), lowerFor (iterate), and an identifier-arm catch-all for
call/other. Storage binds a placeholder so there is no cascade error.

Suggestions point at WORKING fixes -- materialize (..xs), or declare the slice
form ..xs: []P for runtime use. The plan category-B "spread ..xs" is broken
(spreading a comptime pack into a []Any param crashes the LLVM verifier; filed
issue 0053), so the diagnostics steer to the slice-of-protocol variadic instead.

Repurposed examples/162-pack-bare-args.sx (was an aspirational bare-$args->[]Any
auto-materialise, contradicting Decision 1) into the slice-form forward
(..args: []Any). examples/203 is the four-category negative test. specs.md "Pack
as value" updated. 238 examples + unit green.
2026-05-30 02:09:41 +03:00

24 lines
717 B
Plaintext

// Step 2.7 — forwarding a variadic to a `[]Any` helper.
//
// A comptime pack `..$args` is comptime-only (Decision 1): `args` bare is NOT a
// runtime value, so `log_count(args)` on a pack is an error (see the
// pack-as-value tests). To forward a variadic to a runtime `[]Any` helper,
// declare it as the *slice* variadic `..args: []Any` — then `args` is a real
// `[]Any` slice that passes straight through.
#import "modules/std.sx";
log_count :: (items: []Any) -> s64 {
return items.len;
}
// Slice variadic: `args` is a runtime []Any, forwarded directly.
forward :: (..args: []Any) -> s64 {
return log_count(args);
}
main :: () -> s32 {
print("{}\n", forward(1, "hi", 2.5));
return 0;
}