[ruby/yarp] Better handle invalid gvar writes

https://github.com/ruby/yarp/commit/eaaebc17c8
This commit is contained in:
Kevin Newton 2023-09-13 09:14:20 -04:00 коммит произвёл git
Родитель ea75a682a9
Коммит f9898b9eca
2 изменённых файлов: 7 добавлений и 4 удалений

Просмотреть файл

@ -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)

Просмотреть файл

@ -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;