fix ai修复出现的stage2和stage3问题
This commit is contained in:
1 parent
50ee126d44
commit
936a8d0e88
19 files changed
+667
-679
No files matched your search
+30
-6
@@ -230,6 +230,11 @@ fn analyze_fn_decl(self: *Sema, di: usize) {
|
||||
is_va = true;
|
||||
} else {
|
||||
is_va = true;
|
||||
if !x.is_comptime {
|
||||
SemaM.sema_error_code_at(self, pref, ErrorCode.VarargsNotAllowed,
|
||||
"variadic parameter is only allowed in macro/comptime functions",
|
||||
"");
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -299,14 +304,33 @@ fn analyze_value_decl(self: *Sema, di: usize) {
|
||||
if n == null { ret; }
|
||||
var ty: usize = 0;
|
||||
var init: Ref = 0;
|
||||
var is_var = false;
|
||||
var has_ty = false;
|
||||
match n.kind {
|
||||
.VarDecl(x) => { ty = SemaM.resolve_type(self, x.ty); init = x.init; },
|
||||
.ConstDecl(x) => { ty = SemaM.resolve_type(self, x.ty); init = x.init; },
|
||||
.VarDecl(x) => {
|
||||
init = x.init;
|
||||
is_var = true;
|
||||
has_ty = x.ty != 0;
|
||||
if has_ty { ty = SemaM.resolve_decl_type(self, x.ty, init); }
|
||||
},
|
||||
.ConstDecl(x) => {
|
||||
init = x.init;
|
||||
has_ty = x.ty != 0;
|
||||
if has_ty { ty = SemaM.resolve_decl_type(self, x.ty, init); }
|
||||
},
|
||||
_ => { ret; },
|
||||
}
|
||||
if ty == 0 {
|
||||
SemaM.sema_expr(self, init, 0);
|
||||
ty = SemaM.tid_of(self, init);
|
||||
if has_ty {
|
||||
// 声明类型存在但 `[_]T` 推断失败:错误已报,建 def 防止连锁。
|
||||
} else if init == 0 {
|
||||
SemaM.sema_error_code_at(self, node, ErrorCode.MissingDeclType,
|
||||
"declaration requires a type or an initializer", "");
|
||||
ret;
|
||||
} else {
|
||||
SemaM.sema_expr(self, init, 0);
|
||||
ty = SemaM.tid_of(self, init);
|
||||
}
|
||||
} else {
|
||||
SemaM.sema_expr(self, init, ty);
|
||||
}
|
||||
@@ -319,7 +343,7 @@ fn analyze_value_decl(self: *Sema, di: usize) {
|
||||
}
|
||||
var gidx = self.nglobals;
|
||||
self.nglobals = self.nglobals + 1;
|
||||
var def = SemaM.new_global_def(self, ty, gidx);
|
||||
var def = SemaM.new_global_def(self, ty, gidx, is_var);
|
||||
SemaM.set_def(self, node, def);
|
||||
SemaM.decl_at(self, di).gidx = gidx + 1;
|
||||
SemaM.decl_at(self, di).def = def;
|
||||
@@ -413,7 +437,7 @@ fn bind_param(self: *Sema, ref: Ref) {
|
||||
match n.kind {
|
||||
.ParamDecl(x) => {
|
||||
var t = SemaM.resolve_param(self, ref);
|
||||
var d = SemaM.new_def(self, t);
|
||||
var d = SemaM.new_def(self, t, true);
|
||||
SemaM.set_def(self, ref, d);
|
||||
},
|
||||
_ => {},
|
||||
|
||||
Reference in new issue
Block a user