Skip to content

Commit

Permalink
[ruby/prism] Fix up invalid global variable error message
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton authored and matzbot committed Apr 9, 2024
1 parent d101ec6 commit 0107954
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions prism/prism.c
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions test/prism/errors_test.rb
Expand Up @@ -1257,9 +1257,10 @@ def test_invalid_operator_write_dot
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
Expand Down

0 comments on commit 0107954

Please sign in to comment.