Skip to content

Commit fd7c44f

Browse files
committed
Check class name to be a constant path node or a constant read node
1 parent 89b59b0 commit fd7c44f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/yarp.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12304,6 +12304,11 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) {
1230412304
yp_constant_id_list_t locals = parser->current_scope->locals;
1230512305
yp_parser_scope_pop(parser);
1230612306
yp_do_loop_stack_pop(parser);
12307+
12308+
if (!YP_NODE_TYPE_P(constant_path, YP_CONSTANT_PATH_NODE) && !(YP_NODE_TYPE_P(constant_path, YP_CONSTANT_READ_NODE))) {
12309+
yp_diagnostic_list_append(&parser->error_list, constant_path->location.start, constant_path->location.end, YP_ERR_CLASS_NAME);
12310+
}
12311+
1230712312
return (yp_node_t *) yp_class_node_create(parser, &locals, &class_keyword, constant_path, &name, &inheritance_operator, superclass, statements, &parser->previous);
1230812313
}
1230912314
case YP_TOKEN_KEYWORD_DEF: {

test/yarp/errors_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,13 @@ def test_parameter_name_ending_with_bang_or_question_mark
13331333
assert_errors expression(source), source, errors, compare_ripper: false
13341334
end
13351335

1336+
def test_class_name
1337+
source = "class 0.X end"
1338+
assert_errors expression(source), source, [
1339+
["Expected a constant name after `class`", 6..9],
1340+
]
1341+
end
1342+
13361343
private
13371344

13381345
def assert_errors(expected, source, errors, compare_ripper: RUBY_ENGINE == "ruby")

0 commit comments

Comments
 (0)