Skip to content

Commit

Permalink
stage2: make the tests pass with -Denable-qemu
Browse files Browse the repository at this point in the history
  • Loading branch information
g-w1 committed Dec 29, 2020
1 parent 1e2d899 commit bae5a43
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/Module.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2935,11 +2935,10 @@ pub fn coerce(self: *Module, scope: *Scope, dest_type: Type, inst: *Inst) !*Inst
.anyerror => {
switch (gotten_err_set) {
.multiple => |fields| {
fields.deinit(self.gpa); // deinit the hashmap
inst.ty = Type.initTag(.anyerror);
return inst;
},
.err_single => |_| { // dont have to deinit anything because it is a slice
.err_single => |_| {
inst.ty = Type.initTag(.anyerror);
return inst;
},
Expand Down
10 changes: 6 additions & 4 deletions src/zir_sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1419,11 +1419,13 @@ fn validateSwitch(mod: *Module, scope: *Scope, target: *Inst, inst: *zir.Inst.Sw
continue;
} else if (is_single and !mem.eql(u8, gotten_err_set.err_single, err_name)) {
return mod.fail(scope, item.src, "expected type '{}', found '{}'", .{ gotten_err_set.err_single, gotten_err_set.err_single });
} else if (gotten_err_set == .multiple) { // we know it is an actual error set
if (gotten_err_set.multiple.get(err_name)) |_| {} else {
return mod.fail(scope, item.src, "'{}' not a member of destination error set", .{err_name});
}
}
// TODO print this error, but it will never happen because coerce will handle it above
// else if (gotten_err_set == .multiple) { // we know it is an actual error set
// if (gotten_err_set.multiple.get(err_name) == null) {
// return mod.fail(scope, item.src, "'{}' not a member of destination error set", .{err_name});
// }
// }
}
if (!is_single and !is_anyerror and gotten_err_set.multiple.size > inst.positionals.items.len and !(inst.kw_args.special_prong == .@"else"))
return mod.fail(scope, inst.base.src, "switch must handle all possibilities", .{});
Expand Down
12 changes: 6 additions & 6 deletions test/stage2/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ pub fn addCases(ctx: *TestContext) !void {
\\ : [number] "{rax}" (1),
\\ [arg1] "{rdi}" (1),
\\ [arg2] "{rsi}" (@ptrToInt("Reached\n")),
\\ [arg3] "{rdx}" (9)
\\ [arg3] "{rdx}" (8)
\\ : "rcx", "r11", "memory"
\\ );
\\ return;
Expand All @@ -362,7 +362,7 @@ pub fn addCases(ctx: *TestContext) !void {
\\ }
\\ unreachable; // because it will give error above
\\}
, &[_][]const u8{":8:12: error: 'error.Z' not a member of destination error set"});
, &[_][]const u8{":6:14: error: expected _start__anon_13, found error{Z}"});
case.addError(
\\export fn _start() noreturn {
\\ const T = error{ A, B, C, D };
Expand All @@ -373,7 +373,7 @@ pub fn addCases(ctx: *TestContext) !void {
\\ }
\\ unreachable; // because it will give error above
\\}
, &[_][]const u8{":7:6: error: switch must handle all possibilities"});
, &[_][]const u8{":5:5: error: switch must handle all possibilities"});
case.addError(
\\export fn _start() noreturn {
\\ const T = error{ A, B, C, D };
Expand All @@ -384,7 +384,7 @@ pub fn addCases(ctx: *TestContext) !void {
\\ }
\\ unreachable; // because it will give error above
\\}
, &[_][]const u8{":7:6: error: else prong required when switching on type 'anyerror'"});
, &[_][]const u8{":5:5: error: else prong required when switching on type 'anyerror'"});
}
{
var case = ctx.exe("merge error sets", linux_x64);
Expand Down Expand Up @@ -513,7 +513,7 @@ pub fn addCases(ctx: *TestContext) !void {
\\ :
\\ : [number] "{rax}" (1),
\\ [arg1] "{rdi}" (1),
\\ [arg2] "{rsi}" (@ptrToInt("The errs Were Equal\n")),
\\ [arg2] "{rsi}" (@ptrToInt("The errs were equal\n")),
\\ [arg3] "{rdx}" (20)
\\ : "rcx", "r11", "memory"
\\ );
Expand All @@ -530,7 +530,7 @@ pub fn addCases(ctx: *TestContext) !void {
\\ unreachable;
\\}
,
"The Types Were Equal\n",
"The errs were equal\n",
);
}
{
Expand Down

0 comments on commit bae5a43

Please sign in to comment.