mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
parent
bb6b4f8db2
commit
f464fe14f4
10
src/ir.cpp
10
src/ir.cpp
@ -13174,6 +13174,16 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
|
|||||||
return tag_type;
|
return tag_type;
|
||||||
}
|
}
|
||||||
case TypeTableEntryIdEnum: {
|
case TypeTableEntryIdEnum: {
|
||||||
|
type_ensure_zero_bits_known(ira->codegen, target_type);
|
||||||
|
if (type_is_invalid(target_type))
|
||||||
|
return ira->codegen->builtin_types.entry_invalid;
|
||||||
|
if (target_type->data.enumeration.src_field_count < 2) {
|
||||||
|
TypeEnumField *only_field = &target_type->data.enumeration.fields[0];
|
||||||
|
ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
|
||||||
|
bigint_init_bigint(&out_val->data.x_enum_tag, &only_field->value);
|
||||||
|
return target_type;
|
||||||
|
}
|
||||||
|
|
||||||
if (pointee_val) {
|
if (pointee_val) {
|
||||||
ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
|
ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
|
||||||
bigint_init_bigint(&out_val->data.x_enum_tag, &pointee_val->data.x_enum_tag);
|
bigint_init_bigint(&out_val->data.x_enum_tag, &pointee_val->data.x_enum_tag);
|
||||||
|
|||||||
@ -366,3 +366,14 @@ fn doALoopThing(id: EnumWithOneMember) {
|
|||||||
test "comparison operator on enum with one member is comptime known" {
|
test "comparison operator on enum with one member is comptime known" {
|
||||||
doALoopThing(EnumWithOneMember.Eof);
|
doALoopThing(EnumWithOneMember.Eof);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const State = enum {
|
||||||
|
Start,
|
||||||
|
};
|
||||||
|
test "switch on enum with one member is comptime known" {
|
||||||
|
var state = State.Start;
|
||||||
|
switch (state) {
|
||||||
|
State.Start => return,
|
||||||
|
}
|
||||||
|
@compileError("analysis should not reach here");
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user