From f87e43f23a7752b979d5f6dda6232dce3293aa55 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 26 Jul 2019 16:11:33 -0700 Subject: [PATCH] Warn $; $, $/ $\ $. outside of ruby -e Fixes [Bug #14240] --- parse.y | 14 +++++++++----- test/ruby/test_syntax.rb | 8 ++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/parse.y b/parse.y index 46c263fa7b..fe23d6ef98 100644 --- a/parse.y +++ b/parse.y @@ -8347,17 +8347,21 @@ parse_gvar(struct parser_params *p, const enum lex_state_e last_state) pushback(p, c); c = '_'; /* fall through */ + case '/': /* $/: input record separator */ + case '\\': /* $\: output record separator */ + case ';': /* $;: field separator */ + case ',': /* $,: output field separator */ + case '.': /* $.: last read line number */ + if (c != '_' && strcmp(p->ruby_sourcefile, "-e")) { + rb_warn("global variable $%c is deprecated", c); + } + /* fall through */ case '~': /* $~: match-data */ case '*': /* $*: argv */ case '$': /* $$: pid */ case '?': /* $?: last status */ case '!': /* $!: error string */ case '@': /* $@: error position */ - case '/': /* $/: input record separator */ - case '\\': /* $\: output record separator */ - case ';': /* $;: field separator */ - case ',': /* $,: output field separator */ - case '.': /* $.: last read line number */ case '=': /* $=: ignorecase */ case ':': /* $:: load path */ case '<': /* $<: reading filename */ diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index c5c3737b30..a8748462e4 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -605,6 +605,14 @@ def test_unassignable end end + def test_deprecated_global_variable + assert_warning(/global variable \$; is deprecated/) { eval('$;') } + assert_warning(/global variable \$, is deprecated/) { eval('$,') } + assert_warning(/global variable \$\/ is deprecated/) { eval('$/') } + assert_warning(/global variable \$\\ is deprecated/) { eval('$\\') } + assert_warning(/global variable \$\. is deprecated/) { eval('$.') } + end + Bug7559 = '[ruby-dev:46737]' def test_lineno_command_call_quote -- 2.21.0