fix(0118): cast accepts compound type args; compound type literals are first-class Type values
This commit is contained in:
27
examples/0182-types-cast-compound-types.sx
Normal file
27
examples/0182-types-cast-compound-types.sx
Normal 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));
|
||||
}
|
||||
1
examples/expected/0182-types-cast-compound-types.exit
Normal file
1
examples/expected/0182-types-cast-compound-types.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
1
examples/expected/0182-types-cast-compound-types.stderr
Normal file
1
examples/expected/0182-types-cast-compound-types.stderr
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
6
examples/expected/0182-types-cast-compound-types.stdout
Normal file
6
examples/expected/0182-types-cast-compound-types.stdout
Normal file
@@ -0,0 +1,6 @@
|
||||
a: 42
|
||||
b: 42
|
||||
c: 42
|
||||
d: 7
|
||||
e: 3 3
|
||||
f: *s64
|
||||
Reference in New Issue
Block a user