Skip to content

Commit

Permalink
enum tag values are expressions so no parentheses needed
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Jan 3, 2018
1 parent 5c988cc commit 5b15603
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser.cpp
Expand Up @@ -2552,7 +2552,7 @@ static AstNode *ast_parse_container_decl(ParseContext *pc, size_t *token_index,
Token *eq_token = &pc->tokens->at(*token_index);
if (eq_token->id == TokenIdEq) {
*token_index += 1;
field_node->data.struct_field.value = ast_parse_prefix_op_expr(pc, token_index, true);
field_node->data.struct_field.value = ast_parse_expression(pc, token_index, true);
}

Token *next_token = &pc->tokens->at(*token_index);
Expand Down
10 changes: 10 additions & 0 deletions test/cases/enum.zig
Expand Up @@ -377,3 +377,13 @@ test "switch on enum with one member is comptime known" {
}
@compileError("analysis should not reach here");
}

const EnumWithTagValues = enum(u4) {
A = 1 << 0,
B = 1 << 1,
C = 1 << 2,
D = 1 << 3,
};
test "enum with tag values don't require parens" {
assert(u4(EnumWithTagValues.C) == 0b0100);
}

0 comments on commit 5b15603

Please sign in to comment.