authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-03 16:05:37-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-03 16:05:37-05:00
log5b156031e92c66c1bea71d5eb6c337b23185d65d
tree5c8bfbed8f6b555ea15ac11226bc97bf1669fcfa
parent5c988cc7222db9b1a943ba0dd40f7f6116813bcb

enum tag values are expressions so no parentheses needed


2 files changed, 11 insertions(+), 1 deletions(-)

src/parser.cpp+1-1
......@@ -2552,7 +2552,7 @@ static AstNode *ast_parse_container_decl(ParseContext *pc, size_t *token_index,
25522552 Token *eq_token = &pc->tokens->at(*token_index);
25532553 if (eq_token->id == TokenIdEq) {
25542554 *token_index += 1;
2555 field_node->data.struct_field.value = ast_parse_prefix_op_expr(pc, token_index, true);
2555 field_node->data.struct_field.value = ast_parse_expression(pc, token_index, true);
25562556 }
25572557
25582558 Token *next_token = &pc->tokens->at(*token_index);
test/cases/enum.zig+10
......@@ -377,3 +377,13 @@ test "switch on enum with one member is comptime known" {
377377 }
378378 @compileError("analysis should not reach here");
379379}
380
381const EnumWithTagValues = enum(u4) {
382 A = 1 << 0,
383 B = 1 << 1,
384 C = 1 << 2,
385 D = 1 << 3,
386};
387test "enum with tag values don't require parens" {
388 assert(u4(EnumWithTagValues.C) == 0b0100);
389}