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.
26 lines
882 B
Plaintext
26 lines
882 B
Plaintext
// Step 2.7 — pack-as-value diagnostics. A pack is comptime-only (Decision 1),
|
|
// so using the bare pack name where a runtime value is required is an error,
|
|
// with a context-tailored suggestion. All four categories below fire (the
|
|
// functions are monomorphized when called from main).
|
|
|
|
#import "modules/std.sx";
|
|
|
|
Show :: protocol { show :: () -> string; }
|
|
A :: struct {}
|
|
impl Show for A { show :: (self: *A) -> string => "A"; }
|
|
|
|
sink :: (v: s64) -> void { _ = v; }
|
|
|
|
storage :: (..xs: Show) -> void { y := xs; _ = y; } // A: store
|
|
call :: (..xs: Show) -> void { sink(xs); } // B: pass to a call
|
|
ret :: (..xs: Show) -> s64 { return xs; } // C: return
|
|
iter :: (..xs: Show) -> void { for xs : (x) { _ = x; } } // D: runtime iterate
|
|
|
|
main :: () -> s32 {
|
|
storage(A.{});
|
|
call(A.{});
|
|
_ = ret(A.{});
|
|
iter(A.{});
|
|
0;
|
|
}
|