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.
This commit is contained in:
@@ -1,25 +1,19 @@
|
||||
// Variadic heterogeneous type packs — follow-up #3 (bare `args`
|
||||
// reference). The pack-mono doesn't materialise a slice value
|
||||
// for the pack name itself, so any body that references `args`
|
||||
// without indexing (e.g. forwarding to a `[]Any`-typed helper,
|
||||
// or just computing `args.len` through a non-comptime path)
|
||||
// fails with "unresolved 'args'".
|
||||
// Step 2.7 — forwarding a variadic to a `[]Any` helper.
|
||||
//
|
||||
// Next commit materialises an `[]Any` slice on demand inside
|
||||
// the mono: each pack param is boxed into Any, stored in a
|
||||
// stack [N x Any] array, and the slice {data_ptr, len} is bound
|
||||
// to the pack name. `args` then resolves as a runtime value
|
||||
// like the pre-2b inline path did.
|
||||
// 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";
|
||||
|
||||
// Helper that takes a slice. Today the pack body can't pass
|
||||
// `args` here because `args` isn't in scope as a value.
|
||||
log_count :: (items: []Any) -> s64 {
|
||||
return items.len;
|
||||
}
|
||||
|
||||
forward :: (..$args) -> s64 {
|
||||
// Slice variadic: `args` is a runtime []Any, forwarded directly.
|
||||
forward :: (..args: []Any) -> s64 {
|
||||
return log_count(args);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user