Fix issue when using ct types as body parameters.

This commit is contained in:
Christoffer Lerno
2022-12-09 00:00:33 +01:00
parent 13cb637cb4
commit 2a4d43d7c7
5 changed files with 16 additions and 14 deletions

View File

@@ -611,9 +611,9 @@ typedef enum
case TOKEN_UPTR: case TOKEN_USHORT: case TOKEN_USIZE:\ case TOKEN_UPTR: case TOKEN_USHORT: case TOKEN_USIZE:\
case TOKEN_USZ: case TOKEN_ISZ: case TOKEN_FLOAT128: case TOKEN_TYPEID: case TOKEN_ANYERR: case TOKEN_VARIANT case TOKEN_USZ: case TOKEN_ISZ: case TOKEN_FLOAT128: case TOKEN_TYPEID: case TOKEN_ANYERR: case TOKEN_VARIANT
#define TYPE_TOKENS NON_VOID_TYPE_TOKENS: case TOKEN_VOID #define TYPE_TOKENS NON_VOID_TYPE_TOKENS: case TOKEN_VOID
#define TYPELIKE_TOKENS TYPE_TOKENS: case TOKEN_TYPE_IDENT: \ #define CT_TYPE_TOKENS TOKEN_CT_TYPE_IDENT: case TOKEN_CT_TYPEOF: case TOKEN_CT_EVALTYPE: \
case TOKEN_CT_TYPE_IDENT: case TOKEN_CT_TYPEOF: case TOKEN_CT_EVALTYPE: \
case TOKEN_CT_VATYPE: case TOKEN_CT_TYPEFROM case TOKEN_CT_VATYPE: case TOKEN_CT_TYPEFROM
#define TYPELIKE_TOKENS TYPE_TOKENS: case TOKEN_TYPE_IDENT: case CT_TYPE_TOKENS
// Note that ordering matters here. If ordering is changed, // Note that ordering matters here. If ordering is changed,
// So must type_find_max_type and friends. // So must type_find_max_type and friends.

View File

@@ -725,14 +725,14 @@ static Expr *parse_call_expr(ParseContext *c, Expr *left)
params = VECNEW(Expr*, 4); params = VECNEW(Expr*, 4);
if (!parse_arg_list(c, &params, TOKEN_RPAREN, &splat, true)) return poisoned_expr; if (!parse_arg_list(c, &params, TOKEN_RPAREN, &splat, true)) return poisoned_expr;
} }
if (try_consume(c, TOKEN_EOS) && !tok_is(c, TOKEN_RPAREN)) if (try_consume(c, TOKEN_EOS))
{ {
if (!parse_next_may_be_type_or_ident(c)) if (!parse_next_may_be_type_or_ident(c))
{ {
SEMA_ERROR_LAST("Expected an ending ')'. Did you forget a ')' before this ';'?"); SEMA_ERROR_LAST("Expected an ending ')'. Did you forget a ')' before this ';'?");
return poisoned_expr; return poisoned_expr;
} }
if (!parse_parameters(c, VISIBLE_LOCAL, &body_args, NULL, NULL, NULL)) return poisoned_expr; if (!parse_parameters(c, VISIBLE_LOCAL, &body_args, NULL, NULL, NULL, true)) return poisoned_expr;
} }
if (!tok_is(c, TOKEN_RPAREN)) if (!tok_is(c, TOKEN_RPAREN))
{ {

View File

@@ -1127,7 +1127,7 @@ static inline bool parse_param_decl(ParseContext *c, Visibility parent_visibilit
return true; return true;
} }
bool parse_next_is_typed_parameter(ParseContext *c) static bool parse_next_is_typed_parameter(ParseContext *c, bool is_body_param)
{ {
switch (c->tok) switch (c->tok)
{ {
@@ -1138,6 +1138,8 @@ bool parse_next_is_typed_parameter(ParseContext *c)
case TYPE_TOKENS: case TYPE_TOKENS:
case TOKEN_TYPE_IDENT: case TOKEN_TYPE_IDENT:
return true; return true;
case CT_TYPE_TOKENS:
return is_body_param;
default: default:
return false; return false;
} }
@@ -1154,7 +1156,7 @@ INLINE bool is_end_of_param_list(ParseContext *c)
* | ELLIPSIS (CT_TYPE_IDENT | non_type_ident ('=' expr)?)? * | ELLIPSIS (CT_TYPE_IDENT | non_type_ident ('=' expr)?)?
*/ */
bool parse_parameters(ParseContext *c, Visibility visibility, Decl ***params_ref, Decl **body_params, bool parse_parameters(ParseContext *c, Visibility visibility, Decl ***params_ref, Decl **body_params,
Variadic *variadic, int *vararg_index_ref) Variadic *variadic, int *vararg_index_ref, bool is_body_params)
{ {
Decl** params = NULL; Decl** params = NULL;
bool var_arg_found = false; bool var_arg_found = false;
@@ -1194,7 +1196,7 @@ bool parse_parameters(ParseContext *c, Visibility visibility, Decl ***params_ref
// Now we have the following possibilities: "foo", "Foo foo", "Foo... foo", "foo...", "Foo" // Now we have the following possibilities: "foo", "Foo foo", "Foo... foo", "foo...", "Foo"
TypeInfo *type = NULL; TypeInfo *type = NULL;
if (parse_next_is_typed_parameter(c)) if (parse_next_is_typed_parameter(c, is_body_params))
{ {
// Parse the type, // Parse the type,
ASSIGN_TYPE_OR_RET(type, parse_optional_type(c), false); ASSIGN_TYPE_OR_RET(type, parse_optional_type(c), false);
@@ -1373,7 +1375,7 @@ static inline bool parse_fn_parameter_list(ParseContext *c, Visibility parent_vi
CONSUME_OR_RET(TOKEN_LPAREN, false); CONSUME_OR_RET(TOKEN_LPAREN, false);
Variadic variadic = VARIADIC_NONE; Variadic variadic = VARIADIC_NONE;
int vararg_index = -1; int vararg_index = -1;
if (!parse_parameters(c, parent_visibility, &decls, NULL, &variadic, &vararg_index)) return false; if (!parse_parameters(c, parent_visibility, &decls, NULL, &variadic, &vararg_index, false)) return false;
CONSUME_OR_RET(TOKEN_RPAREN, false); CONSUME_OR_RET(TOKEN_RPAREN, false);
signature->vararg_index = vararg_index < 0 ? vec_size(decls) : vararg_index; signature->vararg_index = vararg_index < 0 ? vec_size(decls) : vararg_index;
signature->params = decls; signature->params = decls;
@@ -1621,7 +1623,7 @@ static bool parse_macro_arguments(ParseContext *c, Visibility visibility, Decl *
Variadic variadic = VARIADIC_NONE; Variadic variadic = VARIADIC_NONE;
int vararg_index = -1; int vararg_index = -1;
Decl **params = NULL; Decl **params = NULL;
if (!parse_parameters(c, visibility, &params, NULL, &variadic, &vararg_index)) return false; if (!parse_parameters(c, visibility, &params, NULL, &variadic, &vararg_index, false)) return false;
macro->func_decl.signature.params = params; macro->func_decl.signature.params = params;
macro->func_decl.signature.vararg_index = vararg_index < 0 ? vec_size(params) : vararg_index; macro->func_decl.signature.vararg_index = vararg_index < 0 ? vec_size(params) : vararg_index;
macro->func_decl.signature.variadic = variadic; macro->func_decl.signature.variadic = variadic;
@@ -1634,7 +1636,7 @@ static bool parse_macro_arguments(ParseContext *c, Visibility visibility, Decl *
TRY_CONSUME_OR_RET(TOKEN_AT_IDENT, "Expected an ending ')' or a block parameter on the format '@block(...).", false); TRY_CONSUME_OR_RET(TOKEN_AT_IDENT, "Expected an ending ')' or a block parameter on the format '@block(...).", false);
if (try_consume(c, TOKEN_LPAREN)) if (try_consume(c, TOKEN_LPAREN))
{ {
if (!parse_parameters(c, visibility, &body_param->body_params, NULL, NULL, NULL)) return false; if (!parse_parameters(c, visibility, &body_param->body_params, NULL, NULL, NULL, false)) return false;
CONSUME_OR_RET(TOKEN_RPAREN, false); CONSUME_OR_RET(TOKEN_RPAREN, false);
} }
macro->func_decl.body_param = declid(body_param); macro->func_decl.body_param = declid(body_param);
@@ -1848,7 +1850,7 @@ static inline Decl *parse_define_attribute(ParseContext *c, Visibility visibilit
if (try_consume(c, TOKEN_LPAREN)) if (try_consume(c, TOKEN_LPAREN))
{ {
if (!parse_parameters(c, visibility, &decl->attr_decl.params, NULL, NULL, NULL)) return poisoned_decl; if (!parse_parameters(c, visibility, &decl->attr_decl.params, NULL, NULL, NULL, false)) return poisoned_decl;
CONSUME_OR_RET(TOKEN_RPAREN, poisoned_decl); CONSUME_OR_RET(TOKEN_RPAREN, poisoned_decl);
} }

View File

@@ -47,8 +47,8 @@ Decl *parse_decl_after_type(ParseContext *c, TypeInfo *type);
Decl *parse_var_decl(ParseContext *c); Decl *parse_var_decl(ParseContext *c);
bool bool
parse_parameters(ParseContext *c, Visibility visibility, Decl ***params_ref, Decl **body_params, Variadic *variadic, parse_parameters(ParseContext *c, Visibility visibility, Decl ***params_ref, Decl **body_params,
int *vararg_index_ref); Variadic *variadic, int *vararg_index_ref, bool is_body_params);
bool parse_arg_list(ParseContext *c, Expr ***result, TokenType param_end, bool *splat, bool vasplat); bool parse_arg_list(ParseContext *c, Expr ***result, TokenType param_end, bool *splat, bool vasplat);
Expr *parse_type_compound_literal_expr_after_type(ParseContext *c, TypeInfo *type_info); Expr *parse_type_compound_literal_expr_after_type(ParseContext *c, TypeInfo *type_info);

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.3.113" #define COMPILER_VERSION "0.3.114"