Skip to content

Commit f946a60

Browse files
committed
fix unreachable on bin op between numeric and undefined
1 parent bda355d commit f946a60

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/ir.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15262,7 +15262,9 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1526215262
case ZigTypeIdInt:
1526315263
case ZigTypeIdFloat:
1526415264
case ZigTypeIdVector:
15265-
zig_unreachable(); // handled with the type_is_numeric checks above
15265+
// one of the operands is undefined, this error will be caught by ir_resolve_const_val
15266+
operator_allowed = true;
15267+
break;
1526615268

1526715269
case ZigTypeIdBool:
1526815270
case ZigTypeIdMetaType:

test/compile_errors.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ const tests = @import("tests.zig");
22
const builtin = @import("builtin");
33

44
pub fn addCases(cases: *tests.CompileErrorContext) void {
5+
cases.add("bin op with numeric and undefined",
6+
\\pub fn main() void {
7+
\\ _ = 2 == undefined;
8+
\\}
9+
, &[_][]const u8{
10+
"tmp.zig:2:14: error: use of undefined value here causes undefined behavior",
11+
});
12+
513
cases.add("slice sentinel mismatch",
614
\\fn foo() [:0]u8 {
715
\\ var x: []u8 = undefined;

0 commit comments

Comments
 (0)