fix(0118): cast accepts compound type args; compound type literals are first-class Type values

This commit is contained in:
agra
2026-06-11 14:09:22 +03:00
parent c229f697bd
commit 03dc10bba3
7 changed files with 77 additions and 17 deletions

View File

@@ -0,0 +1,27 @@
// `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 = *s64;`), 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 : *s64 = @x;
q : *s64 = cast(*s64) p; // no-op pointer cast
print("a: {}\n", q.*);
addr : s64 = xx p;
r : *s64 = cast(*s64) addr; // int → ptr through compound cast
print("b: {}\n", r.*);
mp : [*]s64 = cast([*]s64) p; // ptr → many-pointer
print("c: {}\n", mp[0]);
o : ?s32 = cast(?s32) 7; // optional wrap
print("d: {}\n", o ?? -1);
arr := .[1, 2, 3];
s : []s64 = cast([]s64) arr; // array → slice
print("e: {} {}\n", s.len, s[2]);
t : Type = *s64; // first-class compound Type value
print("f: {}\n", type_name(t));
}

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,6 @@
a: 42
b: 42
c: 42
d: 7
e: 3 3
f: *s64