| author | |
| committer | |
| log | d4bd1b1a602355e9cab179289636f8236f66b6f4 |
| tree | 07af471934307431b6da26d051bc2c94d501ff68 |
| parent | 3c2a43fdcc2d9aeafafe7ef37c7b805e18fac351 |
| parent | 28413ffcbad7817c57fd62d5b9908eabdd43147d |
| signature |
small misc fixes7 files changed, 71 insertions(+), 29 deletions(-)
lib/std/zig/render.zig-8| ... | ... | @@ -2807,14 +2807,6 @@ fn nodeIsBlock(tag: Ast.Node.Tag) bool { |
| 2807 | 2807 | .block_semicolon, |
| 2808 | 2808 | .block_two, |
| 2809 | 2809 | .block_two_semicolon, |
| 2810 | .struct_init_dot, | |
| 2811 | .struct_init_dot_comma, | |
| 2812 | .struct_init_dot_two, | |
| 2813 | .struct_init_dot_two_comma, | |
| 2814 | .array_init_dot, | |
| 2815 | .array_init_dot_comma, | |
| 2816 | .array_init_dot_two, | |
| 2817 | .array_init_dot_two_comma, | |
| 2818 | 2810 | => true, |
| 2819 | 2811 | else => false, |
| 2820 | 2812 | }; |
src/AstGen.zig+2-1| ... | ... | @@ -1730,7 +1730,8 @@ fn structInitExprRlNone( |
| 1730 | 1730 | .container_type = ty_inst, |
| 1731 | 1731 | .name_start = str_index, |
| 1732 | 1732 | }) } } |
| 1733 | else .{ .rl = .none }; | |
| 1733 | else | |
| 1734 | .{ .rl = .none }; | |
| 1734 | 1735 | setExtra(astgen, extra_index, Zir.Inst.StructInitAnon.Item{ |
| 1735 | 1736 | .field_name = str_index, |
| 1736 | 1737 | .init = try expr(gz, scope, sub_ri, field_init), |
src/Sema.zig+37-13| ... | ... | @@ -7669,17 +7669,21 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 7669 | 7669 | error_set.fmt(sema.mod), |
| 7670 | 7670 | }); |
| 7671 | 7671 | } |
| 7672 | if (payload.zigTypeTag() == .Opaque) { | |
| 7673 | return sema.fail(block, rhs_src, "error union with payload of opaque type '{}' not allowed", .{ | |
| 7674 | payload.fmt(sema.mod), | |
| 7672 | try sema.validateErrorUnionPayloadType(block, payload, rhs_src); | |
| 7673 | const err_union_ty = try Type.errorUnion(sema.arena, error_set, payload, sema.mod); | |
| 7674 | return sema.addType(err_union_ty); | |
| 7675 | } | |
| 7676 | ||
| 7677 | fn validateErrorUnionPayloadType(sema: *Sema, block: *Block, payload_ty: Type, payload_src: LazySrcLoc) !void { | |
| 7678 | if (payload_ty.zigTypeTag() == .Opaque) { | |
| 7679 | return sema.fail(block, payload_src, "error union with payload of opaque type '{}' not allowed", .{ | |
| 7680 | payload_ty.fmt(sema.mod), | |
| 7675 | 7681 | }); |
| 7676 | } else if (payload.zigTypeTag() == .ErrorSet) { | |
| 7677 | return sema.fail(block, rhs_src, "error union with payload of error set type '{}' not allowed", .{ | |
| 7678 | payload.fmt(sema.mod), | |
| 7682 | } else if (payload_ty.zigTypeTag() == .ErrorSet) { | |
| 7683 | return sema.fail(block, payload_src, "error union with payload of error set type '{}' not allowed", .{ | |
| 7684 | payload_ty.fmt(sema.mod), | |
| 7679 | 7685 | }); |
| 7680 | 7686 | } |
| 7681 | const err_union_ty = try Type.errorUnion(sema.arena, error_set, payload, sema.mod); | |
| 7682 | return sema.addType(err_union_ty); | |
| 7683 | 7687 | } |
| 7684 | 7688 | |
| 7685 | 7689 | fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -8639,6 +8643,7 @@ fn funcCommon( |
| 8639 | 8643 | const return_type = if (!inferred_error_set or ret_poison) |
| 8640 | 8644 | bare_return_type |
| 8641 | 8645 | else blk: { |
| 8646 | try sema.validateErrorUnionPayloadType(block, bare_return_type, ret_ty_src); | |
| 8642 | 8647 | const node = try sema.gpa.create(Module.Fn.InferredErrorSetListNode); |
| 8643 | 8648 | node.data = .{ .func = new_func }; |
| 8644 | 8649 | maybe_inferred_error_set_node = node; |
| ... | ... | @@ -8650,15 +8655,15 @@ fn funcCommon( |
| 8650 | 8655 | }); |
| 8651 | 8656 | }; |
| 8652 | 8657 | |
| 8653 | if (!bare_return_type.isValidReturnType()) { | |
| 8654 | const opaque_str = if (bare_return_type.zigTypeTag() == .Opaque) "opaque " else ""; | |
| 8658 | if (!return_type.isValidReturnType()) { | |
| 8659 | const opaque_str = if (return_type.zigTypeTag() == .Opaque) "opaque " else ""; | |
| 8655 | 8660 | const msg = msg: { |
| 8656 | 8661 | const msg = try sema.errMsg(block, ret_ty_src, "{s}return type '{}' not allowed", .{ |
| 8657 | opaque_str, bare_return_type.fmt(sema.mod), | |
| 8662 | opaque_str, return_type.fmt(sema.mod), | |
| 8658 | 8663 | }); |
| 8659 | 8664 | errdefer msg.destroy(sema.gpa); |
| 8660 | 8665 | |
| 8661 | try sema.addDeclaredHereNote(msg, bare_return_type); | |
| 8666 | try sema.addDeclaredHereNote(msg, return_type); | |
| 8662 | 8667 | break :msg msg; |
| 8663 | 8668 | }; |
| 8664 | 8669 | return sema.failWithOwnedErrorMsg(msg); |
| ... | ... | @@ -21930,7 +21935,7 @@ fn zirCUndef( |
| 21930 | 21935 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 21931 | 21936 | |
| 21932 | 21937 | const name = try sema.resolveConstString(block, src, extra.operand, "name of macro being undefined must be comptime-known"); |
| 21933 | try block.c_import_buf.?.writer().print("#undefine {s}\n", .{name}); | |
| 21938 | try block.c_import_buf.?.writer().print("#undef {s}\n", .{name}); | |
| 21934 | 21939 | return Air.Inst.Ref.void_value; |
| 21935 | 21940 | } |
| 21936 | 21941 | |
| ... | ... | @@ -29756,6 +29761,25 @@ fn resolvePeerTypes( |
| 29756 | 29761 | continue; |
| 29757 | 29762 | } |
| 29758 | 29763 | }, |
| 29764 | .ErrorSet => { | |
| 29765 | chosen = candidate; | |
| 29766 | chosen_i = candidate_i + 1; | |
| 29767 | if (err_set_ty) |chosen_set_ty| { | |
| 29768 | if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, chosen_set_ty, chosen_ty, src, src)) { | |
| 29769 | continue; | |
| 29770 | } | |
| 29771 | if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, chosen_ty, chosen_set_ty, src, src)) { | |
| 29772 | err_set_ty = chosen_ty; | |
| 29773 | continue; | |
| 29774 | } | |
| 29775 | ||
| 29776 | err_set_ty = try chosen_set_ty.errorSetMerge(sema.arena, chosen_ty); | |
| 29777 | continue; | |
| 29778 | } else { | |
| 29779 | err_set_ty = chosen_ty; | |
| 29780 | continue; | |
| 29781 | } | |
| 29782 | }, | |
| 29759 | 29783 | else => {}, |
| 29760 | 29784 | } |
| 29761 | 29785 |
src/codegen/llvm.zig+7-1| ... | ... | @@ -2273,7 +2273,9 @@ pub const Object = struct { |
| 2273 | 2273 | |
| 2274 | 2274 | const full_di_fields: [2]*llvm.DIType = |
| 2275 | 2275 | if (layout.tag_align >= layout.payload_align) |
| 2276 | .{ tag_di, payload_di } else .{ payload_di, tag_di }; | |
| 2276 | .{ tag_di, payload_di } | |
| 2277 | else | |
| 2278 | .{ payload_di, tag_di }; | |
| 2277 | 2279 | |
| 2278 | 2280 | const full_di_ty = dib.createStructType( |
| 2279 | 2281 | compile_unit_scope, |
| ... | ... | @@ -4162,6 +4164,10 @@ pub const DeclGen = struct { |
| 4162 | 4164 | if (func.data.owner_decl != decl_index) { |
| 4163 | 4165 | return self.lowerDeclRefValue(tv, func.data.owner_decl); |
| 4164 | 4166 | } |
| 4167 | } else if (decl.val.castTag(.extern_fn)) |func| { | |
| 4168 | if (func.data.owner_decl != decl_index) { | |
| 4169 | return self.lowerDeclRefValue(tv, func.data.owner_decl); | |
| 4170 | } | |
| 4165 | 4171 | } |
| 4166 | 4172 | |
| 4167 | 4173 | const is_fn_body = decl.ty.zigTypeTag() == .Fn; |
test/behavior/cast.zig+12| ... | ... | @@ -1541,3 +1541,15 @@ test "single item pointer to pointer to array to slice" { |
| 1541 | 1541 | const z1 = @as([]const i32, @as(*[1]i32, &x)); |
| 1542 | 1542 | try expect(z1[0] == 1234); |
| 1543 | 1543 | } |
| 1544 | ||
| 1545 | test "peer type resolution forms error union" { | |
| 1546 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | |
| 1547 | ||
| 1548 | var foo: i32 = 123; | |
| 1549 | const result = if (foo < 0) switch (-foo) { | |
| 1550 | 0 => unreachable, | |
| 1551 | 42 => error.AccessDenied, | |
| 1552 | else => unreachable, | |
| 1553 | } else @intCast(u32, foo); | |
| 1554 | try expect(try result == 123); | |
| 1555 | } |
test/cases/compile_errors/function_returning_opaque_type.zig+6-6| ... | ... | @@ -1,11 +1,11 @@ |
| 1 | 1 | const FooType = opaque {}; |
| 2 | export fn bar() !FooType { | |
| 2 | export fn bar() FooType { | |
| 3 | 3 | return error.InvalidValue; |
| 4 | 4 | } |
| 5 | export fn bav() !@TypeOf(null) { | |
| 5 | export fn bav() @TypeOf(null) { | |
| 6 | 6 | return error.InvalidValue; |
| 7 | 7 | } |
| 8 | export fn baz() !@TypeOf(undefined) { | |
| 8 | export fn baz() @TypeOf(undefined) { | |
| 9 | 9 | return error.InvalidValue; |
| 10 | 10 | } |
| 11 | 11 | |
| ... | ... | @@ -13,7 +13,7 @@ export fn baz() !@TypeOf(undefined) { |
| 13 | 13 | // backend=stage2 |
| 14 | 14 | // target=native |
| 15 | 15 | // |
| 16 | // :2:18: error: opaque return type 'tmp.FooType' not allowed | |
| 16 | // :2:17: error: opaque return type 'tmp.FooType' not allowed | |
| 17 | 17 | // :1:17: note: opaque declared here |
| 18 | // :5:18: error: return type '@TypeOf(null)' not allowed | |
| 19 | // :8:18: error: return type '@TypeOf(undefined)' not allowed | |
| 18 | // :5:17: error: return type '@TypeOf(null)' not allowed | |
| 19 | // :8:17: error: return type '@TypeOf(undefined)' not allowed |
test/cases/compile_errors/invalid_error_union_payload_type.zig+7| ... | ... | @@ -4,6 +4,12 @@ comptime { |
| 4 | 4 | comptime { |
| 5 | 5 | _ = anyerror!anyerror; |
| 6 | 6 | } |
| 7 | fn someFunction() !anyerror { | |
| 8 | return error.C; | |
| 9 | } | |
| 10 | comptime { | |
| 11 | _ = someFunction; | |
| 12 | } | |
| 7 | 13 | |
| 8 | 14 | // error |
| 9 | 15 | // backend=stage2 |
| ... | ... | @@ -11,3 +17,4 @@ comptime { |
| 11 | 17 | // |
| 12 | 18 | // :2:18: error: error union with payload of opaque type 'anyopaque' not allowed |
| 13 | 19 | // :5:18: error: error union with payload of error set type 'anyerror' not allowed |
| 20 | // :7:20: error: error union with payload of error set type 'anyerror' not allowed |