fixes #2235
parent
ba3d18a80e
commit
6cf7fb1177
|
@ -1158,10 +1158,6 @@ static AstNode *ast_parse_prefix_expr(ParseContext *pc) {
|
||||||
// / Block
|
// / Block
|
||||||
// / CurlySuffixExpr
|
// / CurlySuffixExpr
|
||||||
static AstNode *ast_parse_primary_expr(ParseContext *pc) {
|
static AstNode *ast_parse_primary_expr(ParseContext *pc) {
|
||||||
AstNode *enum_lit = ast_parse_enum_lit(pc);
|
|
||||||
if (enum_lit != nullptr)
|
|
||||||
return enum_lit;
|
|
||||||
|
|
||||||
AstNode *asm_expr = ast_parse_asm_expr(pc);
|
AstNode *asm_expr = ast_parse_asm_expr(pc);
|
||||||
if (asm_expr != nullptr)
|
if (asm_expr != nullptr)
|
||||||
return asm_expr;
|
return asm_expr;
|
||||||
|
@ -1496,6 +1492,7 @@ static AstNode *ast_parse_suffix_expr(ParseContext *pc) {
|
||||||
// <- BUILTINIDENTIFIER FnCallArguments
|
// <- BUILTINIDENTIFIER FnCallArguments
|
||||||
// / CHAR_LITERAL
|
// / CHAR_LITERAL
|
||||||
// / ContainerDecl
|
// / ContainerDecl
|
||||||
|
// / DOT IDENTIFIER
|
||||||
// / ErrorSetDecl
|
// / ErrorSetDecl
|
||||||
// / FLOAT
|
// / FLOAT
|
||||||
// / FnProto
|
// / FnProto
|
||||||
|
@ -1556,6 +1553,10 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) {
|
||||||
if (container_decl != nullptr)
|
if (container_decl != nullptr)
|
||||||
return container_decl;
|
return container_decl;
|
||||||
|
|
||||||
|
AstNode *enum_lit = ast_parse_enum_lit(pc);
|
||||||
|
if (enum_lit != nullptr)
|
||||||
|
return enum_lit;
|
||||||
|
|
||||||
AstNode *error_set_decl = ast_parse_error_set_decl(pc);
|
AstNode *error_set_decl = ast_parse_error_set_decl(pc);
|
||||||
if (error_set_decl != nullptr)
|
if (error_set_decl != nullptr)
|
||||||
return error_set_decl;
|
return error_set_decl;
|
||||||
|
@ -1958,7 +1959,14 @@ static AstNode *ast_parse_field_init(ParseContext *pc) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
Token *name = expect_token(pc, TokenIdSymbol);
|
Token *name = expect_token(pc, TokenIdSymbol);
|
||||||
expect_token(pc, TokenIdEq);
|
if (eat_token_if(pc, TokenIdEq) == nullptr) {
|
||||||
|
// Because ".Name" can also be intepreted as an enum literal, we should put back
|
||||||
|
// those two tokens again so that the parser can try to parse them as the enum
|
||||||
|
// literal later.
|
||||||
|
put_back_token(pc);
|
||||||
|
put_back_token(pc);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
AstNode *expr = ast_expect(pc, ast_parse_expr);
|
AstNode *expr = ast_expect(pc, ast_parse_expr);
|
||||||
|
|
||||||
AstNode *res = ast_create_node(pc, NodeTypeStructValueField, first);
|
AstNode *res = ast_create_node(pc, NodeTypeStructValueField, first);
|
||||||
|
|
|
@ -923,3 +923,18 @@ test "peer type resolution with enum literal" {
|
||||||
expect(Items.two == .two);
|
expect(Items.two == .two);
|
||||||
expect(.two == Items.two);
|
expect(.two == Items.two);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "enum literal in array literal" {
|
||||||
|
const Items = enum {
|
||||||
|
one,
|
||||||
|
two,
|
||||||
|
};
|
||||||
|
|
||||||
|
const array = []Items {
|
||||||
|
.one,
|
||||||
|
.two,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(array[0] == .one);
|
||||||
|
expect(array[1] == .two);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue