Skip to content

Commit

Permalink
implement peer type resolution for enum literals
Browse files Browse the repository at this point in the history
See #683
  • Loading branch information
andrewrk committed Mar 24, 2019
1 parent aff7b38 commit da9d8a6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
10 changes: 10 additions & 0 deletions test/stage1/behavior/enum.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit da9d8a6

Please sign in to comment.