Commit 6b81546454

Jacob Young <jacobly0@users.noreply.github.com>
2023-05-30 10:57:30
Type: fix `@typeName` for `undefined`
1 parent 494d4f9
Changed files (1)
src/type.zig
@@ -288,7 +288,51 @@ pub const Type = struct {
                 }
                 try writer.writeAll("}");
             },
-            .simple_type => |s| return writer.writeAll(@tagName(s)),
+            .simple_type => |s| switch (s) {
+                .f16,
+                .f32,
+                .f64,
+                .f80,
+                .f128,
+                .usize,
+                .isize,
+                .c_char,
+                .c_short,
+                .c_ushort,
+                .c_int,
+                .c_uint,
+                .c_long,
+                .c_ulong,
+                .c_longlong,
+                .c_ulonglong,
+                .c_longdouble,
+                .anyopaque,
+                .bool,
+                .void,
+                .type,
+                .anyerror,
+                .comptime_int,
+                .comptime_float,
+                .noreturn,
+                => return writer.writeAll(@tagName(s)),
+                .null,
+                .undefined,
+                => try writer.print("@TypeOf({s})", .{@tagName(s)}),
+                .enum_literal => try writer.print("@TypeOf(.{s})", .{@tagName(s)}),
+                .atomic_order,
+                .atomic_rmw_op,
+                .calling_convention,
+                .address_space,
+                .float_mode,
+                .reduce_op,
+                .call_modifier,
+                .prefetch_options,
+                .export_options,
+                .extern_options,
+                .type_info,
+                .generic_poison,
+                => unreachable,
+            },
             .struct_type => |struct_type| {
                 if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| {
                     const decl = mod.declPtr(struct_obj.owner_decl);