ai: 生成代码准备重构前的一次提交

This commit is contained in:
zzy committed 2026-11-30 12:58:19 +08:00
1 parent 936a8d0e88
commit 032102f1d7
375 files changed
+4619 -7609

No files matched your search

@@ -0,0 +1,13 @@
// Expect retcode = 0
// §16.5:指针引入间接,递归类型合法。
type Node = struct {
value: i32,
next: *Node,
};
fn main(): void {
var n = Node{ .value = 1 };
@assert(n.value == 1, "field");
}
@@ -0,0 +1,9 @@
// Expect compile_error E0103
// §16.5:值字段自引用产生无限布局,应被拒绝。
type A = struct {
x: A,
};
fn main(): void {}
@@ -0,0 +1,12 @@
// Expect retcode = 0
// §16.5:切片大小与元素无关,自引用合法。
type Bytes = struct {
data: []Bytes,
};
fn main(): void {
var b = Bytes{};
@assert(b.data.len() == 0, "empty slice");
}
@@ -0,0 +1,18 @@
// Expect retcode = 0
// §16.5:互递归函数的依赖环是计算环,不是解析环。
fn even(n: u32): bool {
if n == 0 { ret true; }
ret odd(n - 1);
}
fn odd(n: u32): bool {
if n == 0 { ret false; }
ret even(n - 1);
}
fn main(): void {
@assert(even(4), "even");
@assert(odd(3), "odd");
}
@@ -0,0 +1,14 @@
// Expect retcode = 0
// §16.5:指针字段让递归类型有固定布局。
type Node = struct {
value: i32,
next: *Node,
};
fn main(): void {
var a = Node{ .value = 1 };
var b = Node{ .value = 2, .next = &a };
@assert(b.next.value == 1, "follow pointer");
}
@@ -0,0 +1,11 @@
// Expect compile_error E0103
// §16.5:类型层函数无限展开。
comptime fn loop(T: type): type {
ret loop(T);
}
type A = loop(A);
fn main(): void {}
@@ -0,0 +1,8 @@
// Expect compile_error E0103
// §16.4:类型别名互相依赖构成解析环。
type A = B;
type B = A;
fn main(): void {}
@@ -0,0 +1,18 @@
// Expect retcode = 0
// §16.5:两个类型通过指针互递归,布局仍然有限。
type A = struct {
b: *B,
};
type B = struct {
a: *A,
};
fn main(): void {
var a = A{};
var b = B{ .a = &a };
a.b = &b;
@assert(a.b.a == &a, "mutual pointer");
}
@@ -0,0 +1,13 @@
// Expect retcode = 0
// §16.5:optional 指针是否引入间接尚未确认。
type Node = struct {
value: i32,
next: ?*Node,
};
fn main(): void {
var n = Node{ .value = 1 };
@assert(n.value == 1);
}
@@ -0,0 +1,9 @@
// Expect compile_error E0103
// §16.5:数组需要元素布局,值数组自引用是无限大小。
type A = struct {
x: [4]A,
};
fn main(): void {}
@@ -0,0 +1,13 @@
// Expect compile_error E0103
// §16.5:A 和 B 通过值字段互递归,布局无限。
type A = struct {
b: B,
};
type B = struct {
a: A,
};
fn main(): void {}
+15
View File
@@ -0,0 +1,15 @@
// Expect retcode = 0
// §16.5:指针链写入。
type Node = struct {
value: i32,
next: *Node,
};
fn main(): void {
var a = Node{ .value = 1 };
var b = Node{ .value = 2, .next = &a };
b.next.value = 9;
@assert(a.value == 9, "write through chain");
}
@@ -0,0 +1,12 @@
// Expect retcode = 1
// §8:空指针写入。
type Node = struct {
value: i32,
};
fn main(): void {
var p: *Node = null;
p.value = 1;
}
@@ -0,0 +1,13 @@
// Expect retcode = 0
// §16.5:用指针 + null 表达 optional 递归。
type Node = struct {
value: i32,
next: *Node,
};
fn main(): void {
var n = Node{ .value = 1 };
@assert(n.next == null, "null tail");
}
@@ -0,0 +1,9 @@
// Expect compile_error E0103
// §16.4:三个类型别名构成解析环。
type A = B;
type B = C;
type C = A;
fn main(): void {}