Commit da9d8a6ecf
src/ir.cpp
@@ -9573,6 +9573,21 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
continue;
}
+ if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdEnumLiteral) {
+ TypeEnumField *field = find_enum_type_field(prev_type, cur_inst->value.data.x_enum_literal);
+ if (field != nullptr) {
+ continue;
+ }
+ }
+
+ if (cur_type->id == ZigTypeIdEnum && prev_type->id == ZigTypeIdEnumLiteral) {
+ TypeEnumField *field = find_enum_type_field(cur_type, prev_inst->value.data.x_enum_literal);
+ if (field != nullptr) {
+ prev_inst = cur_inst;
+ continue;
+ }
+ }
+
if (prev_type->id == ZigTypeIdPointer && prev_type->data.pointer.ptr_len == PtrLenC &&
(cur_type->id == ZigTypeIdComptimeInt || cur_type->id == ZigTypeIdInt))
{
test/stage1/behavior/enum.zig
@@ -913,3 +913,13 @@ test "enum literal cast to enum" {
var color2 = Color.Auto;
expect(color1 == color2);
}
+
+test "peer type resolution with enum literal" {
+ const Items = enum {
+ one,
+ two,
+ };
+
+ expect(Items.two == .two);
+ expect(.two == Items.two);
+}