diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2023-09-13 11:21:57 -0400 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2023-09-15 15:14:36 +0000 |
| commit | a4b4ebc7c1cfce912e5b8d2d30bcd9f24897bdc5 (patch) | |
| tree | ccc1f5bb7e62a76a346f39c79377d8115c2f3cf8 | |
| parent | 6031ab18c79c38ab53d91281a13bd59d5824e907 (diff) | |
[ruby/yarp] Error when numbered parameters are written
https://github.com/ruby/yarp/commit/65b536ba12
| -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; |
