diff options
| -rw-r--r-- | test/yarp/errors_test.rb | 12 | ||||
| -rw-r--r-- | yarp/yarp.c | 14 |
2 files changed, 24 insertions, 2 deletions
diff --git a/test/yarp/errors_test.rb b/test/yarp/errors_test.rb index 66a9bcd829..7003dceb38 100644 --- a/test/yarp/errors_test.rb +++ b/test/yarp/errors_test.rb @@ -1194,6 +1194,18 @@ module YARP ] end + def test_writing_numbered_parameter + assert_errors expression("-> { _1 = 0 }"), "-> { _1 = 0 }", [ + ["Token reserved for a numbered parameter", 5..7] + ] + end + + def test_targeting_numbered_parameter + assert_errors expression("-> { _1, = 0 }"), "-> { _1, = 0 }", [ + ["Token reserved for a numbered parameter", 5..7] + ] + end + private def assert_errors(expected, source, errors) diff --git a/yarp/yarp.c b/yarp/yarp.c index 36ca8dc726..d9600f0c8f 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -8301,8 +8301,13 @@ parse_target(yp_parser_t *parser, yp_node_t *target) { target->type = YP_GLOBAL_VARIABLE_TARGET_NODE; return target; case YP_LOCAL_VARIABLE_READ_NODE: - assert(sizeof(yp_local_variable_target_node_t) == sizeof(yp_local_variable_read_node_t)); - target->type = YP_LOCAL_VARIABLE_TARGET_NODE; + if (token_is_numbered_parameter(target->location.start, target->location.end)) { + yp_diagnostic_list_append(&parser->error_list, target->location.start, target->location.end, YP_ERR_PARAMETER_NUMBERED_RESERVED); + } else { + assert(sizeof(yp_local_variable_target_node_t) == sizeof(yp_local_variable_read_node_t)); + target->type = YP_LOCAL_VARIABLE_TARGET_NODE; + } + return target; case YP_INSTANCE_VARIABLE_READ_NODE: assert(sizeof(yp_instance_variable_target_node_t) == sizeof(yp_instance_variable_read_node_t)); @@ -8422,6 +8427,11 @@ parse_write(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_nod return (yp_node_t *) node; } case YP_LOCAL_VARIABLE_READ_NODE: { + if (token_is_numbered_parameter(target->location.start, target->location.end)) { + yp_diagnostic_list_append(&parser->error_list, target->location.start, target->location.end, YP_ERR_PARAMETER_NUMBERED_RESERVED); + return target; + } + yp_local_variable_read_node_t *local_read = (yp_local_variable_read_node_t *) target; yp_constant_id_t constant_id = local_read->name; |
