fix: P1审查修复 — error.c arena化 + Self类型解析 + trait查找加固 + 缓冲区安全

P1-①: error_init/add 从 malloc/realloc/strdup 改为 arena_alloc/arena_strdup
P1-②: impl 方法中 Self 类型在 sema 解析为实际结构体名
P1-③: trait 方法 fallback 增加前缀校验(strncmp),method_name 统一更新
P1-④: codegen args[16] 增加溢出检查,移除 parser 未使用的 mods/uses 数组
新增: 36_self_type.l 集成测试(Self 类型 + trait 方法)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-06 17:09:28 +08:00
parent 17c19fd9b9
commit 466be76fd8
9 changed files with 99 additions and 56 deletions
+28
View File
@@ -0,0 +1,28 @@
trait Eq {
fn eq(self: Self, other: Self) -> bool;
}
struct Point { x: i64, y: i64 }
extend Eq Point {
fn eq(self: Point, other: Point) -> bool {
return self.x == other.x && self.y == other.y;
}
}
fn main() -> i64 {
let p1 = Point { x: 10, y: 20 };
let p2 = Point { x: 10, y: 20 };
let p3 = Point { x: 99, y: 1 };
if p1.eq(p2) {
print_str("same");
} else {
print_str("diff");
}
if p1.eq(p3) {
print_str("same");
} else {
print_str("diff");
}
return 0;
}