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
tests/expected/203-pack-as-value.exit
Normal file
1
tests/expected/203-pack-as-value.exit
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
43
tests/expected/203-pack-as-value.txt
Normal file
43
tests/expected/203-pack-as-value.txt
Normal file
@@ -0,0 +1,43 @@
|
||||
error: pack 'xs' has no runtime value — a pack is comptime-only and can't be used as a value here
|
||||
--> /Users/agra/projects/sx/examples/203-pack-as-value.sx:14:40
|
||||
|
|
||||
14 | storage :: (..xs: Show) -> void { y := xs; _ = y; } // A: store
|
||||
| ^^
|
||||
|
||||
help: to store it, materialize a tuple: `(..xs)`
|
||||
|
|
||||
14 | storage :: (..xs: Show) -> void { y := xs; _ = y; } // A: store
|
||||
| ^^
|
||||
|
||||
error: pack 'xs' has no runtime value — a pack is comptime-only and can't be used as a value here
|
||||
--> /Users/agra/projects/sx/examples/203-pack-as-value.sx:15:40
|
||||
|
|
||||
15 | call :: (..xs: Show) -> void { sink(xs); } // B: pass to a call
|
||||
| ^^
|
||||
|
||||
help: materialize a tuple `(..xs)` to store it, or declare `xs` as a slice variadic `..xs: []P` for runtime use instead of a pack `..xs: P`
|
||||
|
|
||||
15 | call :: (..xs: Show) -> void { sink(xs); } // B: pass to a call
|
||||
| ^^
|
||||
|
||||
error: pack 'xs' has no runtime value — a pack is comptime-only and can't be used as a value here
|
||||
--> /Users/agra/projects/sx/examples/203-pack-as-value.sx:16:42
|
||||
|
|
||||
16 | ret :: (..xs: Show) -> s64 { return xs; } // C: return
|
||||
| ^^
|
||||
|
||||
help: to return it, return a tuple `(..xs)` and make the return type that tuple
|
||||
|
|
||||
16 | ret :: (..xs: Show) -> s64 { return xs; } // C: return
|
||||
| ^^
|
||||
|
||||
error: pack 'xs' has no runtime value — a pack is comptime-only and can't be used as a value here
|
||||
--> /Users/agra/projects/sx/examples/203-pack-as-value.sx:17:39
|
||||
|
|
||||
17 | iter :: (..xs: Show) -> void { for xs : (x) { _ = x; } } // D: runtime iterate
|
||||
| ^^
|
||||
|
||||
help: to iterate at comptime use `inline for 0..xs.len (i)`; for a runtime loop declare it as `..xs: []P` (a protocol slice) instead of a pack
|
||||
|
|
||||
17 | iter :: (..xs: Show) -> void { for xs : (x) { _ = x; } } // D: runtime iterate
|
||||
| ^^
|
||||
Reference in New Issue
Block a user