Fixed error where we didn't expect the return type of a function

This commit is contained in:
Jimmi Holst Christensen 2018-11-13 14:37:03 +01:00
parent 8139c5a516
commit 5b3f7a8e1f

View File

@ -812,7 +812,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) {
AstNode *return_type = nullptr; AstNode *return_type = nullptr;
if (var == nullptr) { if (var == nullptr) {
exmark = eat_token_if(pc, TokenIdBang); exmark = eat_token_if(pc, TokenIdBang);
return_type = ast_parse_type_expr(pc); return_type = ast_expect(pc, ast_parse_type_expr);
} }
AstNode *res = ast_create_node(pc, NodeTypeFnProto, first); AstNode *res = ast_create_node(pc, NodeTypeFnProto, first);
@ -1606,6 +1606,7 @@ static AstNode *ast_parse_suffix_expr(ParseContext *pc) {
// / FLOAT // / FLOAT
// / FnProto // / FnProto
// / GroupedExpr // / GroupedExpr
// / LabeledTypeExpr
// / IDENTIFIER // / IDENTIFIER
// / IfTypeExpr // / IfTypeExpr
// / INTEGER // / INTEGER
@ -1618,7 +1619,6 @@ static AstNode *ast_parse_suffix_expr(ParseContext *pc) {
// / KEYWORD_true // / KEYWORD_true
// / KEYWORD_undefined // / KEYWORD_undefined
// / KEYWORD_unreachable // / KEYWORD_unreachable
// / LabeledTypeExpr
// / STRINGLITERAL // / STRINGLITERAL
// / SwitchExpr // / SwitchExpr
static AstNode *ast_parse_primary_type_expr(ParseContext *pc) { static AstNode *ast_parse_primary_type_expr(ParseContext *pc) {
@ -1682,6 +1682,10 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) {
if (grouped_expr != nullptr) if (grouped_expr != nullptr)
return grouped_expr; return grouped_expr;
AstNode *labeled_type_expr = ast_parse_labeled_type_expr(pc);
if (labeled_type_expr != nullptr)
return labeled_type_expr;
Token *identifier = eat_token_if(pc, TokenIdSymbol); Token *identifier = eat_token_if(pc, TokenIdSymbol);
if (identifier != nullptr) if (identifier != nullptr)
return token_symbol(pc, identifier); return token_symbol(pc, identifier);
@ -1750,10 +1754,6 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) {
if (unreachable != nullptr) if (unreachable != nullptr)
return ast_create_node(pc, NodeTypeUnreachable, unreachable); return ast_create_node(pc, NodeTypeUnreachable, unreachable);
AstNode *labeled_type_expr = ast_parse_labeled_type_expr(pc);
if (labeled_type_expr != nullptr)
return labeled_type_expr;
Token *string_lit = eat_token_if(pc, TokenIdStringLiteral); Token *string_lit = eat_token_if(pc, TokenIdStringLiteral);
if (string_lit != nullptr) { if (string_lit != nullptr) {
AstNode *res = ast_create_node(pc, NodeTypeStringLiteral, string_lit); AstNode *res = ast_create_node(pc, NodeTypeStringLiteral, string_lit);