diff --git a/lib/std/debug.zig b/lib/std/debug.zig index a2cbf88730c9e4aab7727d44ea1ca99c01a7de46..3d06c16d570155a629e270a427da277ea54933d2 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1630,7 +1630,6 @@ fn getSymbolFromDwarf(address: u64, di: *DW.DwarfInfo) !SymbolInfo { .symbol_name = nosuspend di.getSymbolName(address) orelse "???", .compile_unit_name = compile_unit.die.getAttrString(di, DW.AT.name) catch |err| switch (err) { error.MissingDebugInfo, error.InvalidDebugInfo => "???", - else => return err, }, .line_info = nosuspend di.getLineNumberInfo(compile_unit.*, address) catch |err| switch (err) { error.MissingDebugInfo, error.InvalidDebugInfo => null, diff --git a/lib/std/dwarf.zig b/lib/std/dwarf.zig index 12ec357849d9d58a8a1f4d8ba03b696445476aaf..93d744ca5f1fe2c6605007aa08c3faf373b4ba47 100644 --- a/lib/std/dwarf.zig +++ b/lib/std/dwarf.zig @@ -822,7 +822,7 @@ pub const DwarfInfo = struct { // in the list itself. // If no starting value is specified use zero. var base_address = compile_unit.die.getAttrAddr(AT.low_pc) catch |err| switch (err) { - error.MissingDebugInfo => 0, + error.MissingDebugInfo => @as(u64, 0), // TODO https://github.com/ziglang/zig/issues/11135 else => return err, }; diff --git a/src/AstGen.zig b/src/AstGen.zig index 97ca9f0a129eb22d484bc8db48a68178dfb704d6..f54af8d3fb8c98783300293bf1642a5a26c451f5 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -1035,9 +1035,8 @@ fn nosuspendExpr( }); } gz.nosuspend_node = node; - const result = try expr(gz, scope, rl, body_node); - gz.nosuspend_node = 0; - return rvalue(gz, rl, result, node); + defer gz.nosuspend_node = 0; + return expr(gz, scope, rl, body_node); } fn suspendExpr( diff --git a/src/Sema.zig b/src/Sema.zig index 82acbab9e541eee08dbeff725ed97239e2a86921..d813cf374bb78a4f92bb684725623125a7f61287 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -6972,7 +6972,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError return sema.failWithOwnedErrorMsg(block, msg); } - if (special_prong == .@"else") { + if (special_prong == .@"else" and seen_errors.count() == operand_ty.errorSetNames().len) { return sema.fail( block, special_prong_src, @@ -16692,6 +16692,13 @@ fn coerceInMemoryAllowedErrorSets( else => unreachable, } + if (dst_ies.func == sema.owner_func) { + // We are trying to coerce an error set to the current function's + // inferred error set. + try dst_ies.addErrorSet(sema.gpa, src_ty); + return .ok; + } + try sema.resolveInferredErrorSet(block, dest_src, dst_payload.data); // isAnyError might have changed from a false negative to a true positive after resolution. if (dest_ty.isAnyError()) { @@ -18910,7 +18917,7 @@ fn resolvePeerTypes( } const chosen_set_ty = err_set_ty orelse chosen_ty.errorUnionSet(); - const candidate_set_ty = chosen_ty.errorUnionSet(); + const candidate_set_ty = candidate_ty.errorUnionSet(); if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, chosen_set_ty, candidate_set_ty, src, src)) { err_set_ty = chosen_set_ty; diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 32dcb302f697cd9cb2d333e7a3c0ed38d93ccae8..c942a975df69576b41f75848a36240ac0bd3cd41 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -5347,7 +5347,14 @@ pub const FuncGen = struct { if (self.liveness.isUnused(inst)) return null; const llvm_i32 = self.context.intType(32); - const llvm_fn = self.getIntrinsic("llvm.frameaddress", &.{llvm_i32}); + const llvm_fn_name = "llvm.frameaddress.p0i8"; + const llvm_fn = self.dg.object.llvm_module.getNamedFunction(llvm_fn_name) orelse blk: { + const llvm_p0i8 = self.context.intType(8).pointerType(0); + const param_types = [_]*const llvm.Type{llvm_i32}; + const fn_type = llvm.functionType(llvm_p0i8, ¶m_types, param_types.len, .False); + break :blk self.dg.object.llvm_module.addFunction(llvm_fn_name, fn_type); + }; + const params = [_]*const llvm.Value{llvm_i32.constNull()}; const ptr_val = self.builder.buildCall(llvm_fn, ¶ms, params.len, .Fast, .Auto, ""); const llvm_usize = try self.dg.llvmType(Type.usize); diff --git a/test/behavior/error.zig b/test/behavior/error.zig index b3503051fb51d3cf46794f5c24194ef971420540..e6c69f4abf64e05bc2d74cb3c466dc98a6b73335 100644 --- a/test/behavior/error.zig +++ b/test/behavior/error.zig @@ -626,3 +626,26 @@ test "inferred error set equality" { try expect(BarError == BarError); try expect(BazError == BazError); } + +test "peer type resolution of two different error unions" { + const a: error{B}!void = {}; + const b: error{A}!void = {}; + var cond = true; + const err = if (cond) a else b; + try err; +} + +test "coerce error set to the current inferred error set" { + const S = struct { + fn foo() !void { + var a = false; + if (a) { + const b: error{A}!void = error.A; + return b; + } + const b = error.A; + return b; + } + }; + S.foo() catch {}; +} diff --git a/test/behavior/switch.zig b/test/behavior/switch.zig index d99998a34ed93f31f693bfca3f691761a3c3a08c..5c47a24b380d69986b4e10bfc0f9718349f9da0e 100644 --- a/test/behavior/switch.zig +++ b/test/behavior/switch.zig @@ -610,14 +610,11 @@ test "switch on pointer type" { } test "switch on error set with single else" { - if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO - const S = struct { fn doTheTest() !void { var some: error{Foo} = error.Foo; try expect(switch (some) { - else => |a| blk: { - a catch {}; + else => blk: { break :blk true; }, });