improve the error message and test coverage

This commit is contained in:
Andrew Kelley
2019-07-04 00:35:28 -04:00
parent bfe0bf695b
commit 96fd103073
4 changed files with 79 additions and 63 deletions

View File

@@ -2,6 +2,24 @@ const tests = @import("tests.zig");
const builtin = @import("builtin");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"capture group on switch prong with incompatible payload types",
\\const Union = union(enum) {
\\ A: usize,
\\ B: isize,
\\};
\\comptime {
\\ var u = Union{ .A = 8 };
\\ switch (u) {
\\ .A, .B => |e| unreachable,
\\ }
\\}
,
"tmp.zig:8:20: error: capture group with incompatible types",
"tmp.zig:8:9: note: type 'usize' here",
"tmp.zig:8:13: note: type 'isize' here",
);
cases.add(
"wrong type to @hasField",
\\export fn entry() bool {
@@ -6073,21 +6091,4 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
"tmp.zig:5:30: error: expression value is ignored",
"tmp.zig:9:30: error: expression value is ignored",
);
cases.add(
"capture group on switch prong with different payloads",
\\const Union = union(enum) {
\\ A: usize,
\\ B: isize,
\\};
\\comptime {
\\ var u = Union{ .A = 8 };
\\ switch (u) {
\\ .A, .B => |e| unreachable,
\\ }
\\}
,
"tmp.zig:8:20: error: switch prong contains cases with different payloads",
"tmp.zig:8:20: note: payload types are usize and isize",
);
}