diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-18 09:34:40 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-18 09:34:40 +0000 |
commit | 4d1f86a1ffceb3323b4e2fac82dfc40c5a382e9e (patch) | |
tree | ab728d5925c7d423c37a45250808a0303754dbe5 | |
parent | eb3d3dfcc1ad61cb3040acfdf41f71c228b892e4 (diff) |
string.c: warn non-nil $;
* string.c (rb_str_split_m): warn use of non-nil $;.
* string.c (rb_fs_setter): warn when set to non-nil value.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | string.c | 6 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 13 |
3 files changed, 19 insertions, 3 deletions
@@ -36,6 +36,9 @@ sufficient information, see the ChangeLog file or Redmine ary[..3] # identical to ary[0..3] where(sales: ..100) +* Setting <code>$;</code> to non-nil value is warned now. Use of it in + String#split is warned too. + === Core classes updates (outstanding ones only) Enumerable:: @@ -7793,6 +7793,9 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str) else if (!(spat = rb_fs_check(spat))) { rb_raise(rb_eTypeError, "value of $; must be String or Regexp"); } + else { + rb_warn("$; is set to non-nil value"); + } if (split_type != awk) { if (BUILTIN_TYPE(spat) == T_STRING) { rb_encoding *enc2 = STR_ENC_GET(spat); @@ -9918,6 +9921,9 @@ rb_fs_setter(VALUE val, ID id, VALUE *var) "value of %"PRIsVALUE" must be String or Regexp", rb_id2str(id)); } + if (!NIL_P(val)) { + rb_warn("non-nil $; will be deprecated"); + } *var = val; } diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index f308cccbcd..d94c4da7ae 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1702,7 +1702,7 @@ CODE assert_equal([], "".split(//, 1)) ensure - $; = fs + EnvUtil.suppress_warning {$; = fs} end def test_split_with_block @@ -1742,7 +1742,7 @@ CODE result = []; "".split(//, 1) {|s| result << s} assert_equal([], result) ensure - $; = fs + EnvUtil.suppress_warning {$; = fs} end def test_fs @@ -1750,7 +1750,7 @@ CODE $; = [] } - assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + assert_separately(%W[-W0], "#{<<~"begin;"}\n#{<<~'end;'}") bug = '[ruby-core:79582] $; must not be GCed' begin; $; = " " @@ -1760,6 +1760,13 @@ CODE GC.start assert_equal([], "".split, bug) end; + + begin + fs = $; + assert_warn(/\$; will be deprecated/) {$; = " "} + ensure + EnvUtil.suppress_warning {$; = fs} + end end def test_split_encoding |