diff --git a/test/yarp/errors_test.rb b/test/yarp/errors_test.rb index e81a4cfac6..2a032e4f84 100644 --- a/test/yarp/errors_test.rb +++ b/test/yarp/errors_test.rb @@ -1143,6 +1143,12 @@ module YARP ] end + def test_invalid_global_variable_write + assert_errors expression("$',"), "$',", [ + ["Immutable variable as a write target", 0..2] + ] + end + private def assert_errors(expected, source, errors) diff --git a/yarp/yarp.c b/yarp/yarp.c index c7dcf482f7..78747682cb 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -8136,12 +8136,9 @@ parse_target(yp_parser_t *parser, yp_node_t *target) { target->type = YP_CONSTANT_TARGET_NODE; return target; case YP_BACK_REFERENCE_READ_NODE: - assert(sizeof(yp_global_variable_target_node_t) == sizeof(yp_back_reference_read_node_t)); - /* fallthrough */ case YP_NUMBERED_REFERENCE_READ_NODE: - assert(sizeof(yp_global_variable_target_node_t) == sizeof(yp_numbered_reference_read_node_t)); yp_diagnostic_list_append(&parser->error_list, target->location.start, target->location.end, YP_ERR_WRITE_TARGET_READONLY); - /* fallthrough */ + return target; case YP_GLOBAL_VARIABLE_READ_NODE: assert(sizeof(yp_global_variable_target_node_t) == sizeof(yp_global_variable_read_node_t)); target->type = YP_GLOBAL_VARIABLE_TARGET_NODE;