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).
21 lines
765 B
Plaintext
21 lines
765 B
Plaintext
// 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;
|
|
}
|