[ruby/yarp] Check class name to be a constant path node or a constant read node
https://github.com/ruby/yarp/commit/fd7c44f13f
This commit is contained in:
parent
9abaf392b1
commit
6de1a9238b
@ -1333,6 +1333,13 @@ module YARP
|
||||
assert_errors expression(source), source, errors, compare_ripper: false
|
||||
end
|
||||
|
||||
def test_class_name
|
||||
source = "class 0.X end"
|
||||
assert_errors expression(source), source, [
|
||||
["Expected a constant name after `class`", 6..9],
|
||||
]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assert_errors(expected, source, errors, compare_ripper: RUBY_ENGINE == "ruby")
|
||||
|
@ -12304,6 +12304,11 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) {
|
||||
yp_constant_id_list_t locals = parser->current_scope->locals;
|
||||
yp_parser_scope_pop(parser);
|
||||
yp_do_loop_stack_pop(parser);
|
||||
|
||||
if (!YP_NODE_TYPE_P(constant_path, YP_CONSTANT_PATH_NODE) && !(YP_NODE_TYPE_P(constant_path, YP_CONSTANT_READ_NODE))) {
|
||||
yp_diagnostic_list_append(&parser->error_list, constant_path->location.start, constant_path->location.end, YP_ERR_CLASS_NAME);
|
||||
}
|
||||
|
||||
return (yp_node_t *) yp_class_node_create(parser, &locals, &class_keyword, constant_path, &name, &inheritance_operator, superclass, statements, &parser->previous);
|
||||
}
|
||||
case YP_TOKEN_KEYWORD_DEF: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user