[ruby/prism] Check for a semicolon or a newline after the inheritance operator
https://github.com/ruby/prism/commit/0326ba6775
This commit is contained in:
parent
0084bac47a
commit
7799fe90da
@ -92,6 +92,7 @@ static const char* const diagnostic_messages[PM_DIAGNOSTIC_ID_LEN] = {
|
||||
[PM_ERR_CLASS_NAME] = "Expected a constant name after `class`",
|
||||
[PM_ERR_CLASS_SUPERCLASS] = "Expected a superclass after `<`",
|
||||
[PM_ERR_CLASS_TERM] = "Expected an `end` to close the `class` statement",
|
||||
[PM_ERR_CLASS_UNEXPECTED_END] = "Unexpected `end`, expecting ';' or '\n'",
|
||||
[PM_ERR_CONDITIONAL_ELSIF_PREDICATE] = "Expected a predicate expression for the `elsif` statement",
|
||||
[PM_ERR_CONDITIONAL_IF_PREDICATE] = "Expected a predicate expression for the `if` statement",
|
||||
[PM_ERR_CONDITIONAL_PREDICATE_TERM] = "Expected `then` or `;` or '\n'",
|
||||
|
@ -57,6 +57,7 @@ typedef enum {
|
||||
PM_ERR_CLASS_NAME,
|
||||
PM_ERR_CLASS_SUPERCLASS,
|
||||
PM_ERR_CLASS_TERM,
|
||||
PM_ERR_CLASS_UNEXPECTED_END,
|
||||
PM_ERR_CONDITIONAL_ELSIF_PREDICATE,
|
||||
PM_ERR_CONDITIONAL_IF_PREDICATE,
|
||||
PM_ERR_CONDITIONAL_PREDICATE_TERM,
|
||||
|
@ -12304,7 +12304,11 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
|
||||
}
|
||||
|
||||
pm_parser_scope_push(parser, true);
|
||||
accept2(parser, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON);
|
||||
if (inheritance_operator.type != PM_TOKEN_NOT_PROVIDED) {
|
||||
expect2(parser, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON, PM_ERR_CLASS_UNEXPECTED_END);
|
||||
} else {
|
||||
accept2(parser, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON);
|
||||
}
|
||||
pm_node_t *statements = NULL;
|
||||
|
||||
if (!match3(parser, PM_TOKEN_KEYWORD_RESCUE, PM_TOKEN_KEYWORD_ENSURE, PM_TOKEN_KEYWORD_END)) {
|
||||
|
@ -1355,6 +1355,13 @@ module Prism
|
||||
]
|
||||
end
|
||||
|
||||
def test_semicolon_after_inheritance_operator
|
||||
source = "class Foo < Bar end"
|
||||
assert_errors expression(source), source, [
|
||||
["Unexpected `end`, expecting ';' or '\n'", 15..15],
|
||||
]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assert_errors(expected, source, errors, compare_ripper: RUBY_ENGINE == "ruby")
|
||||
|
@ -206,7 +206,7 @@ module Prism
|
||||
|
||||
def test_ClassNode
|
||||
assert_location(ClassNode, "class Foo end")
|
||||
assert_location(ClassNode, "class Foo < Bar end")
|
||||
assert_location(ClassNode, "class Foo < Bar; end")
|
||||
end
|
||||
|
||||
def test_ClassVariableAndWriteNode
|
||||
|
Loading…
x
Reference in New Issue
Block a user