diff --git a/test/yarp/errors_test.rb b/test/yarp/errors_test.rb index 3f621b1c56..3a7396ea14 100644 --- a/test/yarp/errors_test.rb +++ b/test/yarp/errors_test.rb @@ -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") diff --git a/yarp/yarp.c b/yarp/yarp.c index 8fd5392693..fe291d0c3b 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -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: {