Skip to content

Commit

Permalink
Merge pull request #1188 from ruby/handle-invalid-multiple-parameters
Browse files Browse the repository at this point in the history
Handle invalid multiple parameters
  • Loading branch information
kddnewton authored Aug 2, 2023
2 parents 3c8a8f9 + 2f83265 commit 5388773
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/yarp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3221,6 +3221,7 @@ yp_parameters_node_posts_append(yp_parameters_node_t *params, yp_node_t *param)
// Set the rest parameter on a ParametersNode node.
static void
yp_parameters_node_rest_set(yp_parameters_node_t *params, yp_rest_parameter_node_t *param) {
assert(params->rest == NULL);
yp_parameters_node_location_set(params, (yp_node_t *) param);
params->rest = param;
}
Expand All @@ -3235,13 +3236,15 @@ yp_parameters_node_keywords_append(yp_parameters_node_t *params, yp_node_t *para
// Set the keyword rest parameter on a ParametersNode node.
static void
yp_parameters_node_keyword_rest_set(yp_parameters_node_t *params, yp_node_t *param) {
assert(params->keyword_rest == NULL);
yp_parameters_node_location_set(params, param);
params->keyword_rest = param;
}

// Set the block parameter on a ParametersNode node.
static void
yp_parameters_node_block_set(yp_parameters_node_t *params, yp_block_parameter_node_t *param) {
assert(params->block == NULL);
yp_parameters_node_location_set(params, (yp_node_t *) param);
params->block = param;
}
Expand Down Expand Up @@ -8349,7 +8352,13 @@ parse_parameters(
}

yp_block_parameter_node_t *param = yp_block_parameter_node_create(parser, &name, &operator);
yp_parameters_node_block_set(params, param);
if (params->block == NULL) {
yp_parameters_node_block_set(params, param);
} else {
yp_diagnostic_list_append(&parser->error_list, param->base.location.start, param->base.location.end, "Unexpected multiple block parameter");
yp_parameters_node_posts_append(params, (yp_node_t *) param);
}

break;
}
case YP_TOKEN_UDOT_DOT_DOT: {
Expand Down Expand Up @@ -8500,7 +8509,13 @@ parse_parameters(
}

yp_rest_parameter_node_t *param = yp_rest_parameter_node_create(parser, &operator, &name);
yp_parameters_node_rest_set(params, param);
if (params->rest == NULL) {
yp_parameters_node_rest_set(params, param);
} else {
yp_diagnostic_list_append(&parser->error_list, param->base.location.start, param->base.location.end, "Unexpected multiple splat parameters.");
yp_parameters_node_posts_append(params, (yp_node_t *) param);
}

break;
}
case YP_TOKEN_STAR_STAR:
Expand Down Expand Up @@ -8528,7 +8543,13 @@ parse_parameters(
param = (yp_node_t *) yp_keyword_rest_parameter_node_create(parser, &operator, &name);
}

yp_parameters_node_keyword_rest_set(params, param);
if (params->keyword_rest == NULL) {
yp_parameters_node_keyword_rest_set(params, param);
} else {
yp_diagnostic_list_append(&parser->error_list, param->location.start, param->location.end, "Unexpected multiple double splat parameters.");
yp_parameters_node_posts_append(params, param);
}

break;
}
default:
Expand All @@ -8539,7 +8560,13 @@ parse_parameters(
// represent it.
yp_token_t name = not_provided(parser);
yp_rest_parameter_node_t *param = yp_rest_parameter_node_create(parser, &parser->previous, &name);
yp_parameters_node_rest_set(params, param);

if (params->rest == NULL) {
yp_parameters_node_rest_set(params, param);
} else {
yp_diagnostic_list_append(&parser->error_list, param->base.location.start, param->base.location.end, "Unexpected multiple splat parameters.");
yp_parameters_node_posts_append(params, (yp_node_t *) param);
}
} else {
yp_diagnostic_list_append(&parser->error_list, parser->previous.start, parser->previous.end, "Unexpected ','.");
}
Expand Down

0 comments on commit 5388773

Please sign in to comment.