Files
sx/examples/0804-memory-xx-target-in-field-assign.sx
agra 4e942b5373 test: migrate examples to XXXX-category-name layout + split expected streams
Rename all example tests/companions to the XXXX-category-test-name scheme
(per-category 100-blocks: basic 0010, types 0100, ... errors 1000,
diagnostics 1100, ffi 1200, ffi-objc 1300, ffi-jni 1400, vectors 1500,
platform 1600). Companions and dir/C fixtures move in lockstep with their
parent test; #import/#source/#include paths rewritten to match.

Expected output now lives in examples/expected/ (a sibling dir of the
tests) split into three streams per the new convention:
  <name>.exit / <name>.stdout / <name>.stderr  (+ optional <name>.ir)

run_examples.sh rewritten: scans examples/ and issues/ for an
expected/<name>.exit marker, captures stdout and stderr separately (no
more 2>&1), compares each stream + exit + optional IR snapshot.

Behavior validated unchanged: every renamed test reproduces its prior
merged output + exit (diffs limited to file paths/basenames embedded in
diagnostics + traces, which correctly reflect the new names). Suite:
292 passed, 0 failed. 50-smoke.sx split + issue relocation + docs follow
in subsequent commits.
2026-06-01 19:05:15 +03:00

43 lines
1.2 KiB
Plaintext

// `xx` cast inside an RHS expression assigned to a struct field takes its
// target type from the field, not from the enclosing function's return type.
// Covers if-then-else RHS and binary-op RHS variants.
#import "modules/std.sx";
Foo :: struct {
pixel_w: s32;
dpi: f32;
last_perf: s64;
delta_time: f32;
}
FC :: struct { a: f32; b: f32; c: s32; d: s32; e: f32; f: f32; }
// If-then-else RHS in a function whose return type is not f32.
calc_bool :: (self: *Foo, wf: f32) -> bool {
self.dpi = if wf > 0.0 then xx self.pixel_w / wf else 1.0;
true;
}
// Binary-op RHS in a struct-returning function. The xx casts must target f32,
// not the FC return-struct shape.
begin :: (self: *Foo, current: s64, freq: s64) -> FC {
if self.last_perf > 0 {
self.delta_time = xx (current - self.last_perf) / xx freq;
}
FC.{ a = 1.0, b = 2.0, c = 3, d = 4, e = 5.0, f = 6.0 };
}
main :: () -> void {
f : *Foo = xx malloc(size_of(Foo));
f.pixel_w = 2880;
f.dpi = 0.0;
f.last_perf = 1000;
f.delta_time = 0.0;
_ := calc_bool(f, 1440.0);
print("dpi={}\n", f.dpi);
fc := begin(f, 1500, 1000);
print("delta={} fc.a={}\n", f.delta_time, fc.a);
}