diff --git a/examples/171-pack-dynamic-type-name.sx b/examples/171-pack-dynamic-type-name.sx new file mode 100644 index 0000000..174ef4a --- /dev/null +++ b/examples/171-pack-dynamic-type-name.sx @@ -0,0 +1,34 @@ +// Variadic heterogeneous type packs — step 4A final-slice +// follow-up. `type_name()` 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; +} diff --git a/tests/expected/171-pack-dynamic-type-name.exit b/tests/expected/171-pack-dynamic-type-name.exit new file mode 100644 index 0000000..573541a --- /dev/null +++ b/tests/expected/171-pack-dynamic-type-name.exit @@ -0,0 +1 @@ +0 diff --git a/tests/expected/171-pack-dynamic-type-name.txt b/tests/expected/171-pack-dynamic-type-name.txt new file mode 100644 index 0000000..d3a2664 --- /dev/null +++ b/tests/expected/171-pack-dynamic-type-name.txt @@ -0,0 +1 @@ +s64string