[ruby/prism] Fix up invalid global variable error message

https://github.com/ruby/prism/commit/8ce9ae487f
This commit is contained in:
Kevin Newton 2024-04-09 12:23:27 -04:00 committed by git
parent d101ec65e9
commit 0107954f25
2 changed files with 8 additions and 3 deletions

View File

@ -8404,6 +8404,10 @@ lex_global_variable(pm_parser_t *parser) {
do {
parser->current.end += width;
} while (parser->current.end < parser->end && (width = char_is_identifier(parser, parser->current.end)) > 0);
} else if (pm_char_is_whitespace(peek(parser))) {
// If we get here, then we have a $ followed by whitespace,
// which is not allowed.
pm_parser_err_token(parser, &parser->current, PM_ERR_GLOBAL_VARIABLE_BARE);
} else {
// If we get here, then we have a $ followed by something that
// isn't recognized as a global variable.

View File

@ -1257,9 +1257,10 @@ module Prism
end
def test_unterminated_global_variable
assert_errors expression("$"), "$", [
["'$' without identifiers is not allowed as a global variable name", 0..1]
]
message = "'$' without identifiers is not allowed as a global variable name"
assert_errors expression("$"), "$", [[message, 0..1]]
assert_errors expression("$ "), "$ ", [[message, 0..1]]
end
def test_invalid_global_variable_write