commit 5b156031e92c66c1bea71d5eb6c337b23185d65d (tree)
parent 5c988cc7222db9b1a943ba0dd40f7f6116813bcb
Author: Andrew Kelley <superjoe30@gmail.com>
Date: Wed, 3 Jan 2018 16:05:37 -0500
enum tag values are expressions so no parentheses needed
Diffstat:
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/parser.cpp b/src/parser.cpp
@@ -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);
diff --git a/test/cases/enum.zig b/test/cases/enum.zig
@@ -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);
+}