diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp index a984664cf8..a513bd6ee8 100644 --- a/src/stage1/ir.cpp +++ b/src/stage1/ir.cpp @@ -26022,6 +26022,32 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI return ira->codegen->builtin_types.entry_bool; case ZigTypeIdUnreachable: return ira->codegen->builtin_types.entry_unreachable; + case ZigTypeIdComptimeFloat: + return ira->codegen->builtin_types.entry_num_lit_float; + case ZigTypeIdComptimeInt: + return ira->codegen->builtin_types.entry_num_lit_int; + case ZigTypeIdUndefined: + return ira->codegen->builtin_types.entry_undef; + case ZigTypeIdNull: + return ira->codegen->builtin_types.entry_null; + case ZigTypeIdEnumLiteral: + return ira->codegen->builtin_types.entry_enum_literal; + default: + if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_instr->source_node, payload, UndefBad))) + return ira->codegen->invalid_inst_gen->value->type; + } + switch (tagTypeId) { + case ZigTypeIdInvalid: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdUnreachable: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdEnumLiteral: + zig_unreachable(); case ZigTypeIdInt: { assert(payload->special == ConstValSpecialStatic); assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr)); @@ -26131,14 +26157,6 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI return ira->codegen->invalid_inst_gen->value->type; return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel); } - case ZigTypeIdComptimeFloat: - return ira->codegen->builtin_types.entry_num_lit_float; - case ZigTypeIdComptimeInt: - return ira->codegen->builtin_types.entry_num_lit_int; - case ZigTypeIdUndefined: - return ira->codegen->builtin_types.entry_undef; - case ZigTypeIdNull: - return ira->codegen->builtin_types.entry_null; case ZigTypeIdOptional: { assert(payload->special == ConstValSpecialStatic); assert(payload->type == ir_type_info_get_type(ira, "Optional", nullptr)); @@ -26204,8 +26222,6 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI return get_any_frame_type(ira->codegen, child_type); } - case ZigTypeIdEnumLiteral: - return ira->codegen->builtin_types.entry_enum_literal; case ZigTypeIdFnFrame: { assert(payload->special == ConstValSpecialStatic); assert(payload->type == ir_type_info_get_type(ira, "Frame", nullptr)); diff --git a/test/compile_errors.zig b/test/compile_errors.zig index d2edf53129..f81458ae8b 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2,6 +2,15 @@ const tests = @import("tests.zig"); const std = @import("std"); pub fn addCases(cases: *tests.CompileErrorContext) void { + cases.add("@Type() union payload is undefined", + \\const Foo = @Type(@import("std").builtin.TypeInfo{ + \\ .Struct = undefined, + \\}); + \\comptime { _ = Foo; } + , &[_][]const u8{ + "tmp.zig:1:50: error: use of undefined value here causes undefined behavior", + }); + cases.add("union with too small explicit signed tag type", \\const U = union(enum(i2)) { \\ A: u8,