diff --git a/src/range_set.cpp b/src/range_set.cpp index fd0076191b..9e621d2f13 100644 --- a/src/range_set.cpp +++ b/src/range_set.cpp @@ -40,6 +40,9 @@ void rangeset_sort(RangeSet *rs) { } bool rangeset_spans(RangeSet *rs, BigInt *first, BigInt *last) { + if (rs->src_range_list.length == 0) + return false; + rangeset_sort(rs); const Range *first_range = &rs->src_range_list.at(0).range; diff --git a/test/compile_errors.zig b/test/compile_errors.zig index c23897a51a..04355261f9 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2,6 +2,16 @@ const tests = @import("tests.zig"); const builtin = @import("builtin"); pub fn addCases(cases: *tests.CompileErrorContext) void { + cases.add( + "empty switch on an integer", + \\export fn entry() void { + \\ var x: u32 = 0; + \\ switch(x) {} + \\} + , + "tmp.zig:3:5: error: switch must handle all possibilities", + ); + cases.add( "regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", \\const Foo = struct {