| author | |
| committer | |
| log | 8470b6ea37a82330be2c5ab41460fe58b8cfd4f6 |
| tree | 5d491879869d4f97f78b0e7b62ea0ad09dee24fd |
| parent | 6e7ae66871575a2bf6b15c0f0280b13a57fc59eb |
| signature |
Resolves: #223432 files changed, 49 insertions(+), 2 deletions(-)
src/Zcu.zig+3-2| ... | @@ -1864,15 +1864,16 @@ pub const SrcLoc = struct { | ... | @@ -1864,15 +1864,16 @@ pub const SrcLoc = struct { |
| 1864 | if (want_case_idx.isSpecial()) { | 1864 | if (want_case_idx.isSpecial()) { |
| 1865 | break case; | 1865 | break case; |
| 1866 | } | 1866 | } |
| 1867 | continue; | ||
| 1867 | } | 1868 | } |
| 1868 | 1869 | ||
| 1869 | const is_multi = case.ast.values.len != 1 or | 1870 | const is_multi = case.ast.values.len != 1 or |
| 1870 | node_tags[case.ast.values[0]] == .switch_range; | 1871 | node_tags[case.ast.values[0]] == .switch_range; |
| 1871 | 1872 | ||
| 1872 | if (!want_case_idx.isSpecial()) switch (want_case_idx.kind) { | 1873 | switch (want_case_idx.kind) { |
| 1873 | .scalar => if (!is_multi and want_case_idx.index == scalar_i) break case, | 1874 | .scalar => if (!is_multi and want_case_idx.index == scalar_i) break case, |
| 1874 | .multi => if (is_multi and want_case_idx.index == multi_i) break case, | 1875 | .multi => if (is_multi and want_case_idx.index == multi_i) break case, |
| 1875 | }; | 1876 | } |
| 1876 | 1877 | ||
| 1877 | if (is_multi) { | 1878 | if (is_multi) { |
| 1878 | multi_i += 1; | 1879 | multi_i += 1; |
test/cases/compile_errors/invalid_switch_item.zig created+46| ... | @@ -0,0 +1,46 @@ | ||
| 1 | const E = enum { a, b, c }; | ||
| 2 | var my_e: E = .a; | ||
| 3 | |||
| 4 | export fn f0() void { | ||
| 5 | switch (my_e) { | ||
| 6 | .a => {}, | ||
| 7 | .b => {}, | ||
| 8 | .x => {}, | ||
| 9 | .c => {}, | ||
| 10 | } | ||
| 11 | } | ||
| 12 | |||
| 13 | export fn f1() void { | ||
| 14 | switch (my_e) { | ||
| 15 | else => {}, | ||
| 16 | .x, .y => {}, | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | export fn f2() void { | ||
| 21 | switch (my_e) { | ||
| 22 | else => {}, | ||
| 23 | .a => {}, | ||
| 24 | .x, .y => {}, | ||
| 25 | .b => {}, | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | export fn f3() void { | ||
| 30 | switch (my_e) { | ||
| 31 | .a, .b => {}, | ||
| 32 | .x, .y => {}, | ||
| 33 | else => {}, | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | // error | ||
| 38 | // | ||
| 39 | // :8:10: error: no field named 'x' in enum 'tmp.E' | ||
| 40 | // :1:11: note: enum declared here | ||
| 41 | // :16:10: error: no field named 'x' in enum 'tmp.E' | ||
| 42 | // :1:11: note: enum declared here | ||
| 43 | // :24:10: error: no field named 'x' in enum 'tmp.E' | ||
| 44 | // :1:11: note: enum declared here | ||
| 45 | // :32:10: error: no field named 'x' in enum 'tmp.E' | ||
| 46 | // :1:11: note: enum declared here | ||