summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-09-13 10:23:56 -0400
committergit <svn-admin@ruby-lang.org>2023-09-15 15:14:33 +0000
commit236fe914af897b9310dff920e53b179c607e21a0 (patch)
tree05c5e74d23270e0d34ce5003ebbe25af903ab898
parent1badb09f615b4cb79ca7cc5ebb4736b7b5cccb7e (diff)
[ruby/yarp] Track explicit parameters on blocks
https://github.com/ruby/yarp/commit/99c91931e0
-rw-r--r--yarp/parser.h9
-rw-r--r--yarp/yarp.c5
2 files changed, 11 insertions, 3 deletions
diff --git a/yarp/parser.h b/yarp/parser.h
index 2d6ba0c4e0..610521041e 100644
--- a/yarp/parser.h
+++ b/yarp/parser.h
@@ -277,12 +277,17 @@ typedef struct yp_scope {
// The IDs of the locals in the given scope.
yp_constant_id_list_t locals;
+ // A pointer to the previous scope in the linked list.
+ struct yp_scope *previous;
+
// A boolean indicating whether or not this scope can see into its parent.
// If closed is true, then the scope cannot see into its parent.
bool closed;
- // A pointer to the previous scope in the linked list.
- struct yp_scope *previous;
+ // A boolean indicating whether or not this scope has explicit parameters.
+ // This is necessary to determine whether or not numbered parameters are
+ // allowed.
+ bool explicit_params;
} yp_scope_t;
// This struct represents the overall parser. It contains a reference to the
diff --git a/yarp/yarp.c b/yarp/yarp.c
index bbf3f8cc66..fb7c400311 100644
--- a/yarp/yarp.c
+++ b/yarp/yarp.c
@@ -4720,7 +4720,7 @@ yp_parser_scope_push(yp_parser_t *parser, bool closed) {
yp_scope_t *scope = (yp_scope_t *) malloc(sizeof(yp_scope_t));
if (scope == NULL) return false;
- *scope = (yp_scope_t) { .closed = closed, .previous = parser->current_scope };
+ *scope = (yp_scope_t) { .previous = parser->current_scope, .closed = closed, .explicit_params = false };
yp_constant_id_list_init(&scope->locals);
parser->current_scope = scope;
@@ -9532,6 +9532,7 @@ parse_block(yp_parser_t *parser) {
yp_block_parameters_node_t *parameters = NULL;
if (accept1(parser, YP_TOKEN_PIPE)) {
+ parser->current_scope->explicit_params = true;
yp_token_t block_parameters_opening = parser->previous;
if (match1(parser, YP_TOKEN_PIPE)) {
@@ -13082,6 +13083,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) {
switch (parser->current.type) {
case YP_TOKEN_PARENTHESIS_LEFT: {
+ parser->current_scope->explicit_params = true;
yp_token_t opening = parser->current;
parser_lex(parser);
@@ -13098,6 +13100,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) {
break;
}
case YP_CASE_PARAMETER: {
+ parser->current_scope->explicit_params = true;
yp_accepts_block_stack_push(parser, false);
yp_token_t opening = not_provided(parser);
params = parse_block_parameters(parser, false, &opening, true);