authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-24 18:47:36-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-24 18:47:36-04:00
logda9d8a6ecfb0428ce3d6575905f96fa1661c9b80
tree2c5085a1a6c81887e527d06380c8389ad4c43b5c
parentaff7b38838628a18f384c1f625d71c085c8eee1f
signaturelock-open Commit is signed but in an unrecognized format.

implement peer type resolution for enum literals

See #683

2 files changed, 25 insertions(+), 0 deletions(-)

src/ir.cpp+15
...@@ -9573,6 +9573,21 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -9573,6 +9573,21 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
9573 continue;9573 continue;
9574 }9574 }
95759575
9576 if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdEnumLiteral) {
9577 TypeEnumField *field = find_enum_type_field(prev_type, cur_inst->value.data.x_enum_literal);
9578 if (field != nullptr) {
9579 continue;
9580 }
9581 }
9582
9583 if (cur_type->id == ZigTypeIdEnum && prev_type->id == ZigTypeIdEnumLiteral) {
9584 TypeEnumField *field = find_enum_type_field(cur_type, prev_inst->value.data.x_enum_literal);
9585 if (field != nullptr) {
9586 prev_inst = cur_inst;
9587 continue;
9588 }
9589 }
9590
9576 if (prev_type->id == ZigTypeIdPointer && prev_type->data.pointer.ptr_len == PtrLenC &&9591 if (prev_type->id == ZigTypeIdPointer && prev_type->data.pointer.ptr_len == PtrLenC &&
9577 (cur_type->id == ZigTypeIdComptimeInt || cur_type->id == ZigTypeIdInt))9592 (cur_type->id == ZigTypeIdComptimeInt || cur_type->id == ZigTypeIdInt))
9578 {9593 {
test/stage1/behavior/enum.zig+10
...@@ -913,3 +913,13 @@ test "enum literal cast to enum" {...@@ -913,3 +913,13 @@ test "enum literal cast to enum" {
913 var color2 = Color.Auto;913 var color2 = Color.Auto;
914 expect(color1 == color2);914 expect(color1 == color2);
915}915}
916
917test "peer type resolution with enum literal" {
918 const Items = enum {
919 one,
920 two,
921 };
922
923 expect(Items.two == .two);
924 expect(.two == Items.two);
925}