fix(0057): clear target_type when lowering variadic pack args
An `xx <int>` argument to a variadic `format`/`print` (a comptime `..$args`
pack) segfaulted when the call was inside an imported-module function. Root
cause: lowerPackCall lowered each pack arg with whatever self.target_type was
set to from the surrounding context. A bare arg is unaffected (inferExprType
ignores target_type), but `xx <expr>`'s result type IS target_type — so
`format("…", xx i)` inside a `-> string` fn cast the int to `string`,
monomorphized __pack_string, and ABI-coerced the 4-byte int as a 16-byte string
fat pointer → corruption. Inline it worked only because target_type was null
there; the imported-module path left it set.
Fix: save/clear/restore self.target_type around the pack-arg lowering loop. A
pack arg is independently typed — comptime `..$args` auto-boxes to Any; a value
pack takes its declared element/protocol type — never a leftover outer target.
examples/242-xx-any-pack-cross-module.sx (+ companion fmt.sx) is the regression.
issues/0057 marked resolved. Unblocks ERR E3.3 (the trace.sx formatter formats
frames with `xx frame`).
Gates: zig build, zig build test, bash tests/run_examples.sh (279 passed; lone
failure is the user's uncommitted 213-canonical-map pack WIP).
This commit is contained in:
13
examples/242-xx-any-pack-cross-module.sx
Normal file
13
examples/242-xx-any-pack-cross-module.sx
Normal file
@@ -0,0 +1,13 @@
|
||||
// Regression for issue 0057: `xx <int>` as a variadic `format` arg inside an
|
||||
// imported-module function used to segfault (mis-typed as the enclosing fn's
|
||||
// return type, monomorphizing __pack_string + ABI-coercing the int as a
|
||||
// 16-byte string fat pointer). Now it auto-boxes to Any like the bare form.
|
||||
// The companion module is examples/242-xx-any-pack-cross-module/fmt.sx.
|
||||
|
||||
#import "modules/std.sx";
|
||||
#import "242-xx-any-pack-cross-module/fmt.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
print("{}", build(3));
|
||||
return 0;
|
||||
}
|
||||
20
examples/242-xx-any-pack-cross-module/fmt.sx
Normal file
20
examples/242-xx-any-pack-cross-module/fmt.sx
Normal file
@@ -0,0 +1,20 @@
|
||||
// Companion module for issue-0057 regression. The bug: an `xx <int>` argument
|
||||
// to a variadic `format` (a comptime `..$args` pack), inside a function that
|
||||
// lives in an IMPORTED module, was mis-typed as the enclosing fn's
|
||||
// `target_type` (here `string`) instead of auto-boxing to `Any` — so it
|
||||
// monomorphized `__pack_string` and ABI-coerced the 4-byte int as a 16-byte
|
||||
// string fat pointer, corrupting memory at runtime. Fixed by clearing
|
||||
// `target_type` while lowering pack args.
|
||||
|
||||
#import "modules/std.sx";
|
||||
|
||||
build :: (n: s32) -> string {
|
||||
result := "items:\n";
|
||||
i : s32 = 0;
|
||||
while i < n {
|
||||
line := format(" item {}\n", xx i); // <-- the xx-to-Any pack arg
|
||||
result = concat(result, line);
|
||||
i = i + 1;
|
||||
}
|
||||
result;
|
||||
}
|
||||
Reference in New Issue
Block a user