zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 019537cb2a447fc28365685e71d323092e1830b0 (tree)
parent 8f45e81c840c79097850bb87bbee1303e6d87dd4
Author: Veikka Tuominen <git@vexu.eu>
Date:   Fri,  3 Jun 2022 15:24:58 +0300

Sema: `@sizeOf` function should give an error

Diffstat:
Msrc/Sema.zig | 2+-
Msrc/type.zig | 12++++++++++--
2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -11547,7 +11547,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const ty = try sema.resolveType(block, operand_src, inst_data.operand); switch (ty.zigTypeTag()) { - .Fn => unreachable, + .Fn, .NoReturn, .Undefined, .Null, diff --git a/src/type.zig b/src/type.zig @@ -2035,7 +2035,11 @@ pub const Type = extern union { try writer.writeAll("fn("); for (fn_info.param_types) |param_ty, i| { if (i != 0) try writer.writeAll(", "); - try print(param_ty, writer, mod); + if (param_ty.tag() == .generic_poison) { + try writer.writeAll("anytype"); + } else { + try print(param_ty, writer, mod); + } } if (fn_info.is_var_args) { if (fn_info.param_types.len != 0) { @@ -2052,7 +2056,11 @@ pub const Type = extern union { if (fn_info.alignment != 0) { try writer.print("align({d}) ", .{fn_info.alignment}); } - try print(fn_info.return_type, writer, mod); + if (fn_info.return_type.tag() == .generic_poison) { + try writer.writeAll("anytype"); + } else { + try print(fn_info.return_type, writer, mod); + } }, .error_union => {