aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorJacob G-W <jacoblevgw@gmail.com>2021-07-05 20:17:51 -0400
committerVeikka Tuominen <git@vexu.eu>2021-07-06 07:51:30 +0300
commit6c11e9bb0798f47e8945182e668854e8b225a788 (patch)
tree6c266b0e32c091311f1698a43a5788332dc5ad83 /src/Sema.zig
parentd089b3df7a3bfe3a6f4c160c27daf77dcdf57dae (diff)
downloadzig-6c11e9bb0798f47e8945182e668854e8b225a788.tar.gz
zig-6c11e9bb0798f47e8945182e668854e8b225a788.zip
stage2: add error note for comparing booleans with '||'
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index ea6f4898c5..0d3f7eaf83 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -2566,8 +2566,19 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn
const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
- const lhs_ty = try sema.resolveType(block, lhs_src, extra.lhs);
- const rhs_ty = try sema.resolveType(block, rhs_src, extra.rhs);
+ const lhs = try sema.resolveInst(extra.lhs);
+ const rhs = try sema.resolveInst(extra.rhs);
+ if (rhs.ty.zigTypeTag() == .Bool and lhs.ty.zigTypeTag() == .Bool) {
+ const msg = msg: {
+ const msg = try sema.mod.errMsg(&block.base, lhs_src, "expected error set type, found 'bool'", .{});
+ errdefer msg.destroy(sema.gpa);
+ try sema.mod.errNote(&block.base, src, msg, "'||' merges error sets; 'or' performs boolean OR", .{});
+ break :msg msg;
+ };
+ return sema.mod.failWithOwnedErrorMsg(&block.base, msg);
+ }
+ const rhs_ty = try sema.resolveAirAsType(block, rhs_src, rhs);
+ const lhs_ty = try sema.resolveAirAsType(block, lhs_src, lhs);
if (rhs_ty.zigTypeTag() != .ErrorSet)
return sema.mod.fail(&block.base, rhs_src, "expected error set type, found {}", .{rhs_ty});
if (lhs_ty.zigTypeTag() != .ErrorSet)