Files
sx/examples/types/0182-types-cast-compound-types.sx
agra 66bdc70bf1 test: group examples into per-category folders
Move examples/*.sx and their expected/ snapshots into per-category
subfolders (examples/<category>/...). Folder = leading filename token,
with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus
runner and LSP sweep now discover each category's expected/ dir, while
issues/ stays flat. Example 1058's repo-root-relative companion import
is made file-relative. Path strings embedded in 164 snapshots were
regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
2026-06-21 14:41:34 +03:00

28 lines
1.1 KiB
Plaintext

// `cast(T) expr` accepts any compile-time-resolvable type argument,
// including compound shapes: `*T`, `[*]T`, `?T`, `[]T`. The same lowering
// makes a compound type literal a first-class `Type` value in expression
// position (`t : Type = *i64;`), mirroring named types (`t : Type = f64;`).
// Regression (issue 0118): compound casts fell into the runtime-dispatch
// path and died with "unresolved 'unknown_expr'".
#import "modules/std.sx";
main :: () {
x := 42;
p : *i64 = @x;
q : *i64 = cast(*i64) p; // no-op pointer cast
print("a: {}\n", q.*);
addr : i64 = xx p;
r : *i64 = cast(*i64) addr; // int → ptr through compound cast
print("b: {}\n", r.*);
mp : [*]i64 = cast([*]i64) p; // ptr → many-pointer
print("c: {}\n", mp[0]);
o : ?i32 = cast(?i32) 7; // optional wrap
print("d: {}\n", o ?? -1);
arr := .[1, 2, 3];
s : []i64 = cast([]i64) arr; // array → slice
print("e: {} {}\n", s.len, s[2]);
t : Type = *i64; // first-class compound Type value
print("f: {}\n", type_name(t));
}