Stage1: Add compile error for an empty switch on a integer

This commit is contained in:
Timon Kruiper 2019-11-20 19:34:20 +01:00 committed by Andrew Kelley
parent e3404e3c78
commit 94299d16d1
2 changed files with 13 additions and 0 deletions

View File

@ -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;

View File

@ -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 {