diff --git a/src/ir.cpp b/src/ir.cpp index 29b6eef27a..58db315665 100644 --- a/src/ir.cpp +++ b/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)) { diff --git a/test/stage1/behavior/enum.zig b/test/stage1/behavior/enum.zig index 2be675ea34..f584fc265a 100644 --- a/test/stage1/behavior/enum.zig +++ b/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); +}