fix ai修复出现的stage2和stage3问题
This commit is contained in:
1 parent
50ee126d44
commit
936a8d0e88
19 files changed
+667
-679
No files matched your search
+195
-61
@@ -143,7 +143,7 @@ fn bind_pattern(self: *Sema, ref: Ref, lang: usize) {
|
||||
// 的 Local 指向旧 def,而 pattern bind 写新 def 的槽。
|
||||
var d = SemaM.node_def(self, ref);
|
||||
if d == 0 {
|
||||
d = SemaM.new_def(self, lang);
|
||||
d = SemaM.new_def(self, lang, true);
|
||||
SemaM.set_def(self, ref, d);
|
||||
}
|
||||
SemaM.set_tid(self, ref, lang);
|
||||
@@ -193,6 +193,27 @@ fn bind_pattern(self: *Sema, ref: Ref, lang: usize) {
|
||||
if x.sub != 0 { bind_pattern(self, x.sub, fl); }
|
||||
SemaM.set_tid(self, ref, sl);
|
||||
},
|
||||
.PatFields(xs) => {
|
||||
var sl = lang;
|
||||
if LangType.is_ptr(&self.types, sl) { sl = LangType.elem_of(&self.types, sl); }
|
||||
var i: usize = 0;
|
||||
while i < xs.len {
|
||||
var fnode = Bld.node_ptr(&self.hir, xs[i]);
|
||||
if fnode != null {
|
||||
match fnode.kind {
|
||||
.PatField(pf) => {
|
||||
var idx = LangType.member_idx(&self.types, sl, pf.name);
|
||||
var fl: usize = 0;
|
||||
if idx >= 0 { fl = LangType.member_lang(&self.types, sl, idx as usize); }
|
||||
if pf.sub != 0 { bind_pattern(self, pf.sub, fl); }
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
SemaM.set_tid(self, ref, sl);
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
@@ -271,7 +292,9 @@ fn dispatch_call_value(self: *Sema, ref: Ref, callee: Ref, args: []Ref, ct: usiz
|
||||
if self.shape_hooks.op_method == null { ret false; }
|
||||
var sym = self.shape_hooks.op_method(self as *any, ct, call_shape, "call");
|
||||
if sym == 0 { ret false; }
|
||||
// 参数 sema 可能追加 FnSym 并让 fn_syms 重分配,先保存返回类型。
|
||||
var s = SemaM.sym_at(self, sym - 1);
|
||||
var ret_tid = s.ret_tid;
|
||||
if LangType.fn_param_count(&self.types, s.fn_tid) < 2 { ret false; }
|
||||
var args_t = LangType.fn_param_of(&self.types, s.fn_tid, 1);
|
||||
if args_t == 0 { ret false; }
|
||||
@@ -296,7 +319,7 @@ fn dispatch_call_value(self: *Sema, ref: Ref, callee: Ref, args: []Ref, ct: usiz
|
||||
Vec.drop(&av);
|
||||
var cav: [2]Ref = .[callee, tuple_ref];
|
||||
var call_args = Bld.dup_refs(&self.hir, cav[0..2]);
|
||||
var call = build_op_call(self, sym, call_args, s.ret_tid);
|
||||
var call = build_op_call(self, sym, call_args, ret_tid);
|
||||
var cn = Bld.node_ptr(&self.hir, call);
|
||||
var np = Bld.node_ptr(&self.hir, ref);
|
||||
if cn != null && np != null {
|
||||
@@ -305,7 +328,7 @@ fn dispatch_call_value(self: *Sema, ref: Ref, callee: Ref, args: []Ref, ct: usiz
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
SemaM.set_tid(self, ref, s.ret_tid);
|
||||
SemaM.set_tid(self, ref, ret_tid);
|
||||
ret true;
|
||||
}
|
||||
|
||||
@@ -394,15 +417,18 @@ fn construct_variant_call(self: *Sema, ref: Ref, callee: Ref, args: []Ref): bool
|
||||
}
|
||||
|
||||
fn dispatch_user_binary(self: *Sema, ref: Ref, x: Node.Kind.Binary, lt: usize, sym: usize) {
|
||||
// FnSym 指针不能跨 sema_expr 保存:递归分析可能追加符号并让 fn_syms 重分配。
|
||||
var s = SemaM.sym_at(self, sym - 1);
|
||||
var fn_tid = s.fn_tid;
|
||||
var ret_tid = s.ret_tid;
|
||||
var rhs_want = lt;
|
||||
if LangType.fn_param_count(&self.types, s.fn_tid) > 1 {
|
||||
rhs_want = LangType.fn_param_of(&self.types, s.fn_tid, 1);
|
||||
if LangType.fn_param_count(&self.types, fn_tid) > 1 {
|
||||
rhs_want = LangType.fn_param_of(&self.types, fn_tid, 1);
|
||||
}
|
||||
sema_expr(self, x.rval, rhs_want);
|
||||
if rhs_want != 0 { SemaM.require_type(self, x.rval, rhs_want, "operand"); }
|
||||
|
||||
var out_tid = s.ret_tid;
|
||||
var out_tid = ret_tid;
|
||||
var av: [2]Ref = .[x.lval, x.rval];
|
||||
var args = Bld.dup_refs(&self.hir, av[0..2]);
|
||||
var call = build_op_call(self, sym, args, out_tid);
|
||||
@@ -467,9 +493,10 @@ fn dispatch_user_binary(self: *Sema, ref: Ref, x: Node.Kind.Binary, lt: usize, s
|
||||
|
||||
fn dispatch_user_unary(self: *Sema, ref: Ref, x: Node.Kind.Unary, vt: usize, sym: usize) {
|
||||
var s = SemaM.sym_at(self, sym - 1);
|
||||
var ret_tid = s.ret_tid;
|
||||
var av: [1]Ref = .[x.val];
|
||||
var args = Bld.dup_refs(&self.hir, av[0..1]);
|
||||
var call = build_op_call(self, sym, args, s.ret_tid);
|
||||
var call = build_op_call(self, sym, args, ret_tid);
|
||||
var cn = Bld.node_ptr(&self.hir, call);
|
||||
var np = Bld.node_ptr(&self.hir, ref);
|
||||
if cn != null && np != null {
|
||||
@@ -478,7 +505,7 @@ fn dispatch_user_unary(self: *Sema, ref: Ref, x: Node.Kind.Unary, vt: usize, sym
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
SemaM.set_tid(self, ref, s.ret_tid);
|
||||
SemaM.set_tid(self, ref, ret_tid);
|
||||
}
|
||||
|
||||
fn dispatch_user_index(self: *Sema, ref: Ref, x: Node.Kind.Index, ol: usize): bool {
|
||||
@@ -486,19 +513,21 @@ fn dispatch_user_index(self: *Sema, ref: Ref, x: Node.Kind.Index, ol: usize): bo
|
||||
if sl == 0 || self.shape_hooks.op_method == null { ret false; }
|
||||
var sym = self.shape_hooks.op_method(self as *any, ol, sl, "index");
|
||||
if sym == 0 { ret false; }
|
||||
// FnSym 指针不能跨 sema_expr 保存;先取出类型再递归分析下标。
|
||||
var s = SemaM.sym_at(self, sym - 1);
|
||||
var fn_tid = s.fn_tid;
|
||||
var ptr_ty = s.ret_tid;
|
||||
if !LangType.is_ptr(&self.types, ptr_ty) { ret false; }
|
||||
var item = LangType.elem_of(&self.types, ptr_ty);
|
||||
var idx_want = LangType.usize_lang(&self.types);
|
||||
if LangType.fn_param_count(&self.types, s.fn_tid) > 1 {
|
||||
idx_want = LangType.fn_param_of(&self.types, s.fn_tid, 1);
|
||||
if LangType.fn_param_count(&self.types, fn_tid) > 1 {
|
||||
idx_want = LangType.fn_param_of(&self.types, fn_tid, 1);
|
||||
}
|
||||
sema_expr(self, x.idx, idx_want);
|
||||
if idx_want != 0 { SemaM.require_type(self, x.idx, idx_want, "index"); }
|
||||
var recv_ty = ol;
|
||||
if LangType.fn_param_count(&self.types, s.fn_tid) > 0 {
|
||||
recv_ty = LangType.fn_param_of(&self.types, s.fn_tid, 0);
|
||||
if LangType.fn_param_count(&self.types, fn_tid) > 0 {
|
||||
recv_ty = LangType.fn_param_of(&self.types, fn_tid, 0);
|
||||
}
|
||||
var addr = Bld.construct(&self.hir, .{ .kind = .Addr(x.obj) });
|
||||
SemaM.grow_tables(self);
|
||||
@@ -561,7 +590,7 @@ fn bind_iter_captures(self: *Sema, captures: []Ref, members: []Ref, pattern_type
|
||||
}
|
||||
var d = SemaM.node_def(self, cap);
|
||||
if d == 0 {
|
||||
d = SemaM.new_def(self, ct);
|
||||
d = SemaM.new_def(self, ct, true);
|
||||
SemaM.set_def(self, cap, d);
|
||||
} else {
|
||||
SemaM.set_def_tid(self, d, ct);
|
||||
@@ -598,6 +627,47 @@ fn callee_label(self: *Sema, callee: Ref): []u8 {
|
||||
ret "";
|
||||
}
|
||||
|
||||
// 把一个已解析的声明绑到表达式节点:`Global` 与 `Type.member` 共用。
|
||||
// Fn/Type/Var/Const 的绑定规则只在这里维护,避免两处漂移。
|
||||
fn bind_decl_ref(self: *Sema, ref: Ref, di: usize, want: usize) {
|
||||
var kind = SemaM.decl_at(self, di).kind;
|
||||
SemaM.ensure_decl(self, di);
|
||||
if @enum2int(kind) == @enum2int(DeclKind.Fn) {
|
||||
SemaM.set_node_fn(self, ref, SemaM.decl_at(self, di).sym);
|
||||
SemaM.set_tid(self, ref, SemaM.decl_at(self, di).lang);
|
||||
SemaM.record_call(self, SemaM.decl_at(self, di).sym);
|
||||
ret;
|
||||
}
|
||||
if @enum2int(kind) == @enum2int(DeclKind.Type) {
|
||||
if self.ct.building || (want != 0 && LangType.is_type(&self.types, want)) {
|
||||
// comptime 里类型名是类型值:物化为 ct_handle,供 == 和返回聚合使用。
|
||||
var tl = SemaM.decl_at(self, di).lang;
|
||||
var dn = Bld.node_ptr(&self.hir, SemaM.decl_at(self, di).node);
|
||||
if dn != null {
|
||||
match dn.kind {
|
||||
.TypeDecl(td) => {
|
||||
var rl = SemaM.resolve_type(self, td.ty);
|
||||
if rl != 0 { tl = rl; }
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
var h = SemaM.ct_handle(self, tl);
|
||||
Bld.node_ptr(&self.hir, ref).kind = .LitInt(SemaM.itext(self, h));
|
||||
SemaM.set_tid(self, ref, LangType.make_type(&self.types));
|
||||
} else {
|
||||
SemaM.set_tid(self, ref, SemaM.decl_at(self, di).lang);
|
||||
}
|
||||
ret;
|
||||
}
|
||||
if SemaM.decl_at(self, di).init != 0 {
|
||||
SemaM.set_node_initref(self, ref, SemaM.decl_at(self, di).init);
|
||||
} else {
|
||||
SemaM.set_def(self, ref, SemaM.decl_at(self, di).def);
|
||||
}
|
||||
SemaM.set_tid(self, ref, SemaM.decl_at(self, di).lang);
|
||||
}
|
||||
|
||||
fn sema_expr(self: *Sema, ref: Ref, want: usize) {
|
||||
if ref == 0 { ret; }
|
||||
var n = Bld.node_ptr(&self.hir, ref);
|
||||
@@ -648,6 +718,7 @@ fn sema_expr(self: *Sema, ref: Ref, want: usize) {
|
||||
},
|
||||
.Global(x) => {
|
||||
var d = SemaM.find_decl(self, x);
|
||||
if d == 0 { d = SemaM.find_path_decl(self, x); }
|
||||
if d == 0 {
|
||||
if SemaM.builtin_tid(self, x) == 0 && SemaM.lookup_type(self, x) == 0 {
|
||||
if SemaM.current_fn_is_lambda(self) {
|
||||
@@ -660,45 +731,15 @@ fn sema_expr(self: *Sema, ref: Ref, want: usize) {
|
||||
SemaM.set_tid(self, ref, want);
|
||||
ret;
|
||||
}
|
||||
var di = d - 1;
|
||||
var kind = SemaM.decl_at(self, di).kind;
|
||||
SemaM.ensure_decl(self, di);
|
||||
if @enum2int(kind) == @enum2int(DeclKind.Fn) {
|
||||
SemaM.set_node_fn(self, ref, SemaM.decl_at(self, di).sym);
|
||||
SemaM.set_tid(self, ref, SemaM.decl_at(self, di).lang);
|
||||
SemaM.record_call(self, SemaM.decl_at(self, di).sym);
|
||||
} else if @enum2int(kind) == @enum2int(DeclKind.Type) {
|
||||
if self.ct.building || (want != 0 && LangType.is_type(&self.types, want)) {
|
||||
// comptime 里类型名是类型值:物化为 ct_handle,供 == 和返回聚合使用。
|
||||
var tl = SemaM.decl_at(self, di).lang;
|
||||
var dn = Bld.node_ptr(&self.hir, SemaM.decl_at(self, di).node);
|
||||
if dn != null {
|
||||
match dn.kind {
|
||||
.TypeDecl(td) => {
|
||||
var rl = SemaM.resolve_type(self, td.ty);
|
||||
if rl != 0 { tl = rl; }
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
var h = SemaM.ct_handle(self, tl);
|
||||
Bld.node_ptr(&self.hir, ref).kind = .LitInt(SemaM.itext(self, h));
|
||||
SemaM.set_tid(self, ref, LangType.make_type(&self.types));
|
||||
} else {
|
||||
SemaM.set_tid(self, ref, SemaM.decl_at(self, di).lang);
|
||||
}
|
||||
} else {
|
||||
if SemaM.decl_at(self, di).init != 0 {
|
||||
SemaM.set_node_initref(self, ref, SemaM.decl_at(self, di).init);
|
||||
} else {
|
||||
SemaM.set_def(self, ref, SemaM.decl_at(self, di).def);
|
||||
}
|
||||
SemaM.set_tid(self, ref, SemaM.decl_at(self, di).lang);
|
||||
}
|
||||
bind_decl_ref(self, ref, d - 1, want);
|
||||
},
|
||||
.Import(_) => {
|
||||
var tgt = SemaM.import_target(self, self.cur_mod, ref);
|
||||
if tgt == 0 { SemaM.set_tid(self, ref, 0); ret; }
|
||||
if tgt == 0 {
|
||||
SemaM.sema_error_code_at(self, ref, ErrorCode.ImportFailed, "cannot import module", "");
|
||||
SemaM.set_tid(self, ref, 0);
|
||||
ret;
|
||||
}
|
||||
var tm = tgt - 1;
|
||||
SemaM.ensure_module(self, tm);
|
||||
SemaM.set_tid(self, ref, SemaM.module_at(self, tm).root_lang);
|
||||
@@ -721,6 +762,13 @@ fn sema_expr(self: *Sema, ref: Ref, want: usize) {
|
||||
}
|
||||
SemaM.set_tid(self, ref, want);
|
||||
},
|
||||
.LitChar(_) => {
|
||||
// 字符默认 u8;与整型上下文交互时沿用 LitInt 的重定型规则。
|
||||
if !LangType.is_int(&self.types, want) {
|
||||
want = LangType.make_int(&self.types, 8, false);
|
||||
}
|
||||
SemaM.set_tid(self, ref, want);
|
||||
},
|
||||
.LitFloat(_) => {
|
||||
if !LangType.is_float(&self.types, want) {
|
||||
want = LangType.make_float(&self.types, 64);
|
||||
@@ -799,6 +847,13 @@ fn sema_expr(self: *Sema, ref: Ref, want: usize) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// `Type.member`:容器命名空间里的 var/const/fn/type(Zig container-level)。
|
||||
if sl != 0 && (obj_is_type || SemaM.is_type_ref(self, x.obj)) {
|
||||
var cmod = LangType.container_mod_of(&self.types, sl);
|
||||
var cont = LangType.container_of(&self.types, sl);
|
||||
var d = SemaM.lookup_decl_in_mod(self, cmod, cont, x.name);
|
||||
if d != 0 { bind_decl_ref(self, ref, d - 1, want); ret; }
|
||||
}
|
||||
if ol != 0 && !LangType.is_type(&self.types, ol) &&
|
||||
!LangType.kind_eq(LangType.kind_of(&self.types, ol), .Any) {
|
||||
SemaM.sema_error_code_at(self, ref, ErrorCode.NoField, "no such field", x.name);
|
||||
@@ -807,7 +862,12 @@ fn sema_expr(self: *Sema, ref: Ref, want: usize) {
|
||||
},
|
||||
.AggLit(x) => {
|
||||
var sl: usize = 0;
|
||||
if x.name.len != 0 { sl = SemaM.lookup_type(self, x.name); }
|
||||
// `@self { ... }`:以当前聚合匿名类型构造。
|
||||
if SemaM.eq(x.name, "self") {
|
||||
sl = self.self_lang;
|
||||
if sl == 0 { sl = self.current_agg; }
|
||||
}
|
||||
if sl == 0 && x.name.len != 0 { sl = SemaM.lookup_type(self, x.name); }
|
||||
if sl == 0 && want != 0 && LangType.is_agg(&self.types, want) { sl = want; }
|
||||
if sl == 0 && want != 0 && LangType.is_slice(&self.types, want) {
|
||||
// 切片字面量:字段名到表示槽位由 LangType 的表示层解析。
|
||||
@@ -1013,6 +1073,7 @@ fn sema_expr(self: *Sema, ref: Ref, want: usize) {
|
||||
var prefer_binding = x.is_comptime && bi != 0;
|
||||
var d: usize = 0;
|
||||
if !prefer_binding { d = SemaM.find_decl(self, vx); }
|
||||
if d == 0 && !prefer_binding { d = SemaM.find_path_decl(self, vx); }
|
||||
if d != 0 && @enum2int(SemaM.decl_at(self, d - 1).kind) == @enum2int(DeclKind.Fn) {
|
||||
SemaM.ensure_decl(self, d - 1);
|
||||
fn_tid = SemaM.decl_at(self, d - 1).lang;
|
||||
@@ -1398,6 +1459,7 @@ fn sema_expr(self: *Sema, ref: Ref, want: usize) {
|
||||
},
|
||||
.CompoundAssign(x) => {
|
||||
sema_expr(self, x.lval, want);
|
||||
check_assignable(self, x.lval);
|
||||
SemaM.mark_assigned(self, x.lval);
|
||||
var lt = SemaM.tid_of(self, x.lval);
|
||||
if lt == 0 { lt = want; }
|
||||
@@ -1438,15 +1500,17 @@ fn sema_expr(self: *Sema, ref: Ref, want: usize) {
|
||||
},
|
||||
.User(sym) => {
|
||||
var s = SemaM.sym_at(self, sym - 1);
|
||||
var fn_tid = s.fn_tid;
|
||||
var ret_tid = s.ret_tid;
|
||||
var rhs_want = lt;
|
||||
if LangType.fn_param_count(&self.types, s.fn_tid) > 1 {
|
||||
rhs_want = LangType.fn_param_of(&self.types, s.fn_tid, 1);
|
||||
if LangType.fn_param_count(&self.types, fn_tid) > 1 {
|
||||
rhs_want = LangType.fn_param_of(&self.types, fn_tid, 1);
|
||||
}
|
||||
sema_expr(self, x.rval, rhs_want);
|
||||
if rhs_want != 0 { SemaM.require_type(self, x.rval, rhs_want, "compound assignment"); }
|
||||
var av: [2]Ref = .[x.lval, x.rval];
|
||||
var args = Bld.dup_refs(&self.hir, av[0..2]);
|
||||
var call = build_op_call(self, sym, args, s.ret_tid);
|
||||
var call = build_op_call(self, sym, args, ret_tid);
|
||||
SemaM.require_type(self, call, lt, "compound assignment");
|
||||
var np = Bld.node_ptr(&self.hir, ref);
|
||||
if np != null {
|
||||
@@ -1513,6 +1577,13 @@ fn sema_expr(self: *Sema, ref: Ref, want: usize) {
|
||||
ret;
|
||||
}
|
||||
var op = SemaOpM.binary_op(x.op);
|
||||
if @enum2int(op) == @enum2int(SemaOp.Reserved) {
|
||||
SemaM.sema_error_code_at(self, ref, ErrorCode.OpNotImplemented,
|
||||
"reserved operator", "reserved operator");
|
||||
sema_expr(self, x.rval, lt);
|
||||
SemaM.set_tid(self, ref, lt);
|
||||
ret;
|
||||
}
|
||||
if @enum2int(op) == @enum2int(SemaOp.None) {
|
||||
sema_expr(self, x.rval, lt);
|
||||
if lt != 0 { SemaM.require_type(self, x.rval, lt, "operand"); }
|
||||
@@ -1781,15 +1852,72 @@ fn sema_expr(self: *Sema, ref: Ref, want: usize) {
|
||||
}
|
||||
}
|
||||
|
||||
fn sema_let(self: *Sema, ref: Ref, ret_tid: usize) {
|
||||
// 赋值目标检查:只有 Local / Field / Index / Deref 可写,const 绑定不可写。
|
||||
fn check_assignable(self: *Sema, ref: Ref) {
|
||||
var n = Bld.node_ptr(&self.hir, ref);
|
||||
if n == null { ret; }
|
||||
match n.kind {
|
||||
.Local(x) => {
|
||||
var d = SemaM.node_def(self, x);
|
||||
if d != 0 && !SemaM.def_mutable(self, d) {
|
||||
SemaM.sema_error_code_at(self, ref, ErrorCode.AssignToConst,
|
||||
"cannot assign to const binding", "");
|
||||
}
|
||||
},
|
||||
.Field(x) => {
|
||||
// `S.c`:命名空间全局在 bind_decl_ref 里把 def 挂到 Field 节点上。
|
||||
var d = SemaM.node_def(self, ref);
|
||||
if d != 0 && !SemaM.def_mutable(self, d) {
|
||||
SemaM.sema_error_code_at(self, ref, ErrorCode.AssignToConst,
|
||||
"cannot assign to const binding", "");
|
||||
ret;
|
||||
}
|
||||
// 指针/切片的字段访问是写穿,不要求指针本身是 lvalue。
|
||||
var ot = SemaM.tid_of(self, x.obj);
|
||||
if LangType.is_ptr(&self.types, ot) || LangType.is_slice(&self.types, ot) { ret; }
|
||||
check_assignable(self, x.obj);
|
||||
},
|
||||
.Index(x) => {
|
||||
var ot = SemaM.tid_of(self, x.obj);
|
||||
if LangType.is_ptr(&self.types, ot) || LangType.is_slice(&self.types, ot) { ret; }
|
||||
check_assignable(self, x.obj);
|
||||
},
|
||||
.Deref(_) => {},
|
||||
.Global(x) => {
|
||||
var d = SemaM.node_def(self, ref);
|
||||
if d != 0 && !SemaM.def_mutable(self, d) {
|
||||
SemaM.sema_error_code_at(self, ref, ErrorCode.AssignToConst,
|
||||
"cannot assign to const binding", "");
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
SemaM.sema_error_code_at(self, ref, ErrorCode.NotAssignable,
|
||||
"assignment target is not assignable", "");
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn sema_let(self: *Sema, ref: Ref, ret_tid: usize) { var n = Bld.node_ptr(&self.hir, ref);
|
||||
if n == null { ret; }
|
||||
// 生成方法体可能被重复进入;重复 new_def 会让 Local 读取未初始化槽。
|
||||
if SemaM.node_def(self, ref) != 0 { ret; }
|
||||
match n.kind {
|
||||
.Alloc(x) => {
|
||||
var ty = SemaM.resolve_type(self, x.ty);
|
||||
if ty == 0 {
|
||||
var ty: usize = 0;
|
||||
if x.ty != 0 {
|
||||
ty = SemaM.resolve_decl_type(self, x.ty, x.value);
|
||||
if ty != 0 {
|
||||
sema_expr(self, x.value, ty);
|
||||
SemaM.require_type(self, x.value, ty, "initializer");
|
||||
}
|
||||
} else if x.value == 0 {
|
||||
SemaM.sema_error_code_at(self, ref, ErrorCode.MissingDeclType,
|
||||
"declaration requires a type or an initializer", "");
|
||||
var d0 = SemaM.new_def(self, 0, !x.is_const);
|
||||
SemaM.set_def(self, ref, d0);
|
||||
SemaM.set_tid(self, ref, 0);
|
||||
ret;
|
||||
} else {
|
||||
sema_expr(self, x.value, 0);
|
||||
ty = SemaM.tid_of(self, x.value);
|
||||
if ty == 0 { ty = ret_tid; }
|
||||
@@ -1798,12 +1926,9 @@ fn sema_let(self: *Sema, ref: Ref, ret_tid: usize) {
|
||||
var l = SemaM.ct_lang(self, SemaM.type_handle_arg(self, x.value));
|
||||
if l != 0 { ty = l; }
|
||||
}
|
||||
} else {
|
||||
sema_expr(self, x.value, ty);
|
||||
SemaM.require_type(self, x.value, ty, "initializer");
|
||||
}
|
||||
SemaM.set_tid(self, ref, ty);
|
||||
var d = SemaM.new_def(self, ty);
|
||||
var d = SemaM.new_def(self, ty, !x.is_const);
|
||||
SemaM.set_def(self, ref, d);
|
||||
SemaM.set_def_init(self, d, x.value);
|
||||
},
|
||||
@@ -1848,11 +1973,20 @@ fn sema_stmt(self: *Sema, ref: Ref, ret_tid: usize) {
|
||||
var w: usize = 0;
|
||||
if self.loop_results.len != 0 {
|
||||
w = (self.loop_results.data as *usize)[self.loop_results.len - 1];
|
||||
} else {
|
||||
SemaM.sema_error_code_at(self, ref, ErrorCode.BreakOutsideLoop,
|
||||
"break outside loop", "");
|
||||
}
|
||||
if x.value != 0 { sema_expr(self, x.value, w); }
|
||||
SemaM.set_tid(self, ref, w);
|
||||
},
|
||||
.Continue(_) => { SemaM.set_tid(self, ref, 0); },
|
||||
.Continue(_) => {
|
||||
if self.loop_results.len == 0 {
|
||||
SemaM.sema_error_code_at(self, ref, ErrorCode.ContinueOutsideLoop,
|
||||
"continue outside loop", "");
|
||||
}
|
||||
SemaM.set_tid(self, ref, 0);
|
||||
},
|
||||
.Block(x) => {
|
||||
var i: usize = 0;
|
||||
while i < x.stmts.len {
|
||||
|
||||
Reference in new issue
Block a user