summaryrefslogtreecommitdiff
diff options
-rw-r--r--prism/prism.c4
-rw-r--r--test/prism/errors_test.rb7
2 files changed, 8 insertions, 3 deletions
diff --git a/prism/prism.c b/prism/prism.c
index c394ae95b6..16dad45b37 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -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.
diff --git a/test/prism/errors_test.rb b/test/prism/errors_test.rb
index 79a38b41d0..cabc96c8ea 100644
--- a/test/prism/errors_test.rb
+++ b/test/prism/errors_test.rb
@@ -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