fix: unknown identifier failure in valid case

This commit is contained in:
Brett Broadhurst 2026-04-03 12:53:37 -06:00
parent 19cceb1b35
commit edadc87751
Failed to generate hash of commit

View file

@ -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); _ = try gi.addBinaryNode(.store, decl.inst_index.toRef(), expr_result);
return; return;
} }
return fail(astgen, identifier_node, "unknown identifier", .{}); _ = try gi.addStrTok(.decl_ref, name_str.index, node.loc.start);
} }
fn assignOp( fn assignOp(
@ -1153,8 +1153,14 @@ fn assignOp(
const expr_node = node.data.bin.rhs.?; const expr_node = node.data.bin.rhs.?;
const name_str = try astgen.strFromNode(identifier_node); const name_str = try astgen.strFromNode(identifier_node);
if (scope.lookup(name_str.index)) |decl| { const lhs = if (scope.lookup(name_str.index)) |decl| blk: {
const lhs = try gi.addUnaryNode(.load, decl.inst_index.toRef()); 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 rhs = try expr(gi, scope, expr_node); const rhs = try expr(gi, scope, expr_node);
const result = switch (op_inst_tag) { const result = switch (op_inst_tag) {
@ -1162,10 +1168,7 @@ fn assignOp(
.sub => try gi.addBinaryNode(.sub, lhs, rhs), .sub => try gi.addBinaryNode(.sub, lhs, rhs),
else => unreachable, else => unreachable,
}; };
_ = try gi.addBinaryNode(.store, decl.inst_index.toRef(), result); _ = try gi.addBinaryNode(.store, lhs, result);
return;
}
return fail(astgen, identifier_node, "unknown identifier", .{});
} }
fn choiceStmt(gi: *GenIr, scope: *Scope, node: *const Ast.Node) InnerError!void { fn choiceStmt(gi: *GenIr, scope: *Scope, node: *const Ast.Node) InnerError!void {