fix: unknown identifier failure in valid case
This commit is contained in:
parent
19cceb1b35
commit
edadc87751
1 changed files with 16 additions and 13 deletions
|
|
@ -1139,7 +1139,7 @@ fn assign(gi: *GenIr, scope: *Scope, node: *const Ast.Node) InnerError!void {
|
|||
_ = try gi.addBinaryNode(.store, decl.inst_index.toRef(), expr_result);
|
||||
return;
|
||||
}
|
||||
return fail(astgen, identifier_node, "unknown identifier", .{});
|
||||
_ = try gi.addStrTok(.decl_ref, name_str.index, node.loc.start);
|
||||
}
|
||||
|
||||
fn assignOp(
|
||||
|
|
@ -1153,19 +1153,22 @@ fn assignOp(
|
|||
const expr_node = node.data.bin.rhs.?;
|
||||
const name_str = try astgen.strFromNode(identifier_node);
|
||||
|
||||
if (scope.lookup(name_str.index)) |decl| {
|
||||
const lhs = try gi.addUnaryNode(.load, decl.inst_index.toRef());
|
||||
const rhs = try expr(gi, scope, expr_node);
|
||||
const lhs = if (scope.lookup(name_str.index)) |decl| blk: {
|
||||
const inst_ref = decl.inst_index.toRef();
|
||||
_ = try gi.addUnaryNode(.load, inst_ref);
|
||||
break :blk inst_ref;
|
||||
} else blk: {
|
||||
break :blk try gi.addStrTok(.decl_ref, name_str.index, node.loc.start);
|
||||
};
|
||||
|
||||
const result = switch (op_inst_tag) {
|
||||
.add => try gi.addBinaryNode(.add, lhs, rhs),
|
||||
.sub => try gi.addBinaryNode(.sub, lhs, rhs),
|
||||
else => unreachable,
|
||||
};
|
||||
_ = try gi.addBinaryNode(.store, decl.inst_index.toRef(), result);
|
||||
return;
|
||||
}
|
||||
return fail(astgen, identifier_node, "unknown identifier", .{});
|
||||
const rhs = try expr(gi, scope, expr_node);
|
||||
|
||||
const result = switch (op_inst_tag) {
|
||||
.add => try gi.addBinaryNode(.add, lhs, rhs),
|
||||
.sub => try gi.addBinaryNode(.sub, lhs, rhs),
|
||||
else => unreachable,
|
||||
};
|
||||
_ = try gi.addBinaryNode(.store, lhs, result);
|
||||
}
|
||||
|
||||
fn choiceStmt(gi: *GenIr, scope: *Scope, node: *const Ast.Node) InnerError!void {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue