authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2019-05-11 20:51:59+02:00
committergravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2019-05-11 20:51:59+02:00
log6cf7fb1177848c2f2a20c1f4093b1e003c477911
tree2b9ca820cdd1f6dec58f9e28262b3b67ebc3f066
parentba3d18a80e6b33e943ecebd9aaf07c0a84de84ee

fixes #2235


2 files changed, 28 insertions(+), 5 deletions(-)

src/parser.cpp+13-5
......@@ -1158,10 +1158,6 @@ static AstNode *ast_parse_prefix_expr(ParseContext *pc) {
11581158// / Block
11591159// / CurlySuffixExpr
11601160static AstNode *ast_parse_primary_expr(ParseContext *pc) {
1161 AstNode *enum_lit = ast_parse_enum_lit(pc);
1162 if (enum_lit != nullptr)
1163 return enum_lit;
1164
11651161 AstNode *asm_expr = ast_parse_asm_expr(pc);
11661162 if (asm_expr != nullptr)
11671163 return asm_expr;
......@@ -1496,6 +1492,7 @@ static AstNode *ast_parse_suffix_expr(ParseContext *pc) {
14961492// <- BUILTINIDENTIFIER FnCallArguments
14971493// / CHAR_LITERAL
14981494// / ContainerDecl
1495// / DOT IDENTIFIER
14991496// / ErrorSetDecl
15001497// / FLOAT
15011498// / FnProto
......@@ -1556,6 +1553,10 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) {
15561553 if (container_decl != nullptr)
15571554 return container_decl;
15581555
1556 AstNode *enum_lit = ast_parse_enum_lit(pc);
1557 if (enum_lit != nullptr)
1558 return enum_lit;
1559
15591560 AstNode *error_set_decl = ast_parse_error_set_decl(pc);
15601561 if (error_set_decl != nullptr)
15611562 return error_set_decl;
......@@ -1958,7 +1959,14 @@ static AstNode *ast_parse_field_init(ParseContext *pc) {
19581959 return nullptr;
19591960
19601961 Token *name = expect_token(pc, TokenIdSymbol);
1961 expect_token(pc, TokenIdEq);
1962 if (eat_token_if(pc, TokenIdEq) == nullptr) {
1963 // Because ".Name" can also be intepreted as an enum literal, we should put back
1964 // those two tokens again so that the parser can try to parse them as the enum
1965 // literal later.
1966 put_back_token(pc);
1967 put_back_token(pc);
1968 return nullptr;
1969 }
19621970 AstNode *expr = ast_expect(pc, ast_parse_expr);
19631971
19641972 AstNode *res = ast_create_node(pc, NodeTypeStructValueField, first);
test/stage1/behavior/enum.zig+15
......@@ -923,3 +923,18 @@ test "peer type resolution with enum literal" {
923923 expect(Items.two == .two);
924924 expect(.two == Items.two);
925925}
926
927test "enum literal in array literal" {
928 const Items = enum {
929 one,
930 two,
931 };
932
933 const array = []Items {
934 .one,
935 .two,
936 };
937
938 expect(array[0] == .one);
939 expect(array[1] == .two);
940}