comptime type params

This commit is contained in:
2026-07-02 20:30:02 +02:00
parent a98b26446d
commit b94687c30a
8 changed files with 393 additions and 31 deletions
@@ -0,0 +1,46 @@
Point :: struct {
x i32
}
max func($T type, a, b T) T {
if a > b {
return a
}
return b
}
id func($T type, value T) T {
return value
}
buffer func($T type, $N usize, value T) [N]T {
data [N]T = undefined
_ = value
return data
}
main func() i32 {
a i32 :: 42
b i32 :: 27
if max(i32, a, b) != 42 {
return 1
}
small_a u8 :: 3
small_b u8 :: 9
if max(u8, small_a, small_b) != 9 {
return 2
}
p Point :: Point { x = 11 }
q Point :: id(Point, p)
if q.x != 11 {
return 3
}
bytes [_]u8 :: buffer(u8, 4, small_a)
if bytes.len != 4 {
return 4
}
return 0
}