Step 4A final follow-up's lock-in. `type_name(<arg>)` where
<arg> is NOT a statically resolvable type expression (e.g.
`list[i]` indexing into a `$args`-derived `[]Type` slice)
silently folds to "s64" today because `resolveTypeArg`'s
index_expr fall-through returns `.s64` (the catch-all `else =>
.s64` at the bottom of the switch).
This is exactly the kind of silent unimplemented arm the
project's REJECTED PATTERNS section forbids — the user gets
"s64" for every element of an arbitrary pack, not the per-
position concrete type they expect.
`examples/171-pack-dynamic-type-name.sx` exercises a builder-
shaped fn: walks `$args` via runtime indexing, calls
`type_name(list[i])` per position, concatenates the results.
For `walk(42, "hi")` the expected output is "s64string".
Today's output is "s64s64" — the silent fold strikes twice.
Cadence shape 2: expected output is the WORKING shape; today's
diff fails. Next commit teaches `tryLowerReflectionCall` to
detect "arg not statically resolvable" and emit a builtin_call
to `.type_name` so the interp's runtime arm (wired in commit
9600ba5, M5.A.next.4.1) handles the dynamic case.
210/210 + 1 expected-failing = 211 total. zig build test green.
35 lines
1.0 KiB
Plaintext
35 lines
1.0 KiB
Plaintext
// Variadic heterogeneous type packs — step 4A final-slice
|
|
// follow-up. `type_name(<dynamic-arg>)` where the argument is
|
|
// NOT a static type expression (e.g. `list[i]` indexing into
|
|
// a `$args`-derived `[]Type` slice) silently folds to "s64"
|
|
// today because `resolveTypeArg`'s index_expr fall-through
|
|
// returns `.s64`. That's exactly the kind of silent unimplemented
|
|
// arm the CLAUDE.md REJECTED PATTERNS section forbids.
|
|
//
|
|
// Next commit teaches `tryLowerReflectionCall` to detect "arg
|
|
// not statically resolvable" and emit a `builtin_call` to the
|
|
// new `.type_name` builtin. The interp's arm (already wired in
|
|
// commit 9600ba5) reads the runtime `.type_tag` Value and
|
|
// returns the per-position concrete type name.
|
|
//
|
|
// Expected output after fix:
|
|
// s64string
|
|
|
|
#import "modules/std.sx";
|
|
|
|
walk :: (..$args) -> string {
|
|
list := $args;
|
|
s := "";
|
|
i : s64 = 0;
|
|
while i < list.len {
|
|
s = concat(s, type_name(list[i]));
|
|
i = i + 1;
|
|
}
|
|
return s;
|
|
}
|
|
|
|
main :: () -> s32 {
|
|
print("{}\n", walk(42, "hi"));
|
|
return 0;
|
|
}
|