mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 23:52:31 +00:00
parent
6f88ecc9b6
commit
19961c50e4
@ -3728,6 +3728,7 @@ TypeUnionField *find_union_field_by_tag(TypeTableEntry *type_entry, const BigInt
|
||||
}
|
||||
|
||||
TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *tag) {
|
||||
assert(enum_type->data.enumeration.zero_bits_known);
|
||||
for (uint32_t i = 0; i < enum_type->data.enumeration.src_field_count; i += 1) {
|
||||
TypeEnumField *field = &enum_type->data.enumeration.fields[i];
|
||||
if (bigint_cmp(&field->value, tag) == CmpEQ) {
|
||||
|
@ -16053,6 +16053,9 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIn
|
||||
assert(target->value.type->id == TypeTableEntryIdEnum);
|
||||
|
||||
if (instr_is_comptime(target)) {
|
||||
type_ensure_zero_bits_known(ira->codegen, target->value.type);
|
||||
if (type_is_invalid(target->value.type))
|
||||
return ira->codegen->builtin_types.entry_invalid;
|
||||
TypeEnumField *field = find_enum_field_by_tag(target->value.type, &target->value.data.x_bigint);
|
||||
ConstExprValue *array_val = create_const_str_lit(ira->codegen, field->name);
|
||||
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
|
||||
|
@ -637,3 +637,8 @@ test "call method with comptime pass-by-non-copying-value self parameter" {
|
||||
var b = s.b();
|
||||
assert(b == 2);
|
||||
}
|
||||
|
||||
test "@tagName of @typeId" {
|
||||
const str = @tagName(@typeId(u8));
|
||||
assert(std.mem.eql(u8, str, "Int"));
|
||||
}
|
||||
|
@ -19,8 +19,9 @@ test "implicit unsigned integer to signed integer" {
|
||||
}
|
||||
|
||||
test "float widening" {
|
||||
var a: f32 = 12.34;
|
||||
var b: f64 = a;
|
||||
var c: f128 = b;
|
||||
assert(c == a);
|
||||
var a: f16 = 12.34;
|
||||
var b: f32 = a;
|
||||
var c: f64 = b;
|
||||
var d: f128 = c;
|
||||
assert(d == a);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user