Commit 019537cb2a

Veikka Tuominen <git@vexu.eu>
2022-06-03 14:24:58
Sema: `@sizeOf` function should give an error
1 parent 8f45e81
Changed files (2)
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,
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 => {