From 8a9b15a14053561623cfc3ae02a490a571222902 Mon Sep 17 00:00:00 2001 From: g-w1 Date: Thu, 26 Nov 2020 09:24:32 -0500 Subject: [PATCH] stage2: make the tests pass with -Denable-qemu --- src/Module.zig | 3 +-- src/zir_sema.zig | 10 ++++++---- test/stage2/test.zig | 12 ++++++------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Module.zig b/src/Module.zig index 38fcc83e011f..bd410af3d7a7 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -2861,11 +2861,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; }, diff --git a/src/zir_sema.zig b/src/zir_sema.zig index b79fdd87d50c..be0c1bffeaac 100644 --- a/src/zir_sema.zig +++ b/src/zir_sema.zig @@ -1405,11 +1405,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", .{}); diff --git a/test/stage2/test.zig b/test/stage2/test.zig index 8dadcdade865..c73c5f943e0b 100644 --- a/test/stage2/test.zig +++ b/test/stage2/test.zig @@ -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; @@ -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 }; @@ -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 }; @@ -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); @@ -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" \\ ); @@ -530,7 +530,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ unreachable; \\} , - "The Types Were Equal\n", + "The errs were equal\n", ); } {