Skip to content

Commit ae76c8a

Browse files
authored
1 parent 41c00bc commit ae76c8a

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ changelog for details of the default gems or bundled gems.
257257
removed. Environment variables `RUBY_GC_HEAP_%d_INIT_SLOTS` should be
258258
used instead. [[Feature #19785]]
259259
260+
* `it` calls without arguments in a block with no ordinary parameters are
261+
deprecated. `it` will be a reference to the first block parameter in Ruby 3.4.
262+
[[Feature #18980]]
263+
260264
## Stdlib compatibility issues
261265
262266
* `racc` is promoted to bundled gems.
@@ -374,6 +378,7 @@ changelog for details of the default gems or bundled gems.
374378
[Feature #18515]: https://bugs.ruby-lang.org/issues/18515
375379
[Feature #18551]: https://bugs.ruby-lang.org/issues/18551
376380
[Feature #18885]: https://bugs.ruby-lang.org/issues/18885
381+
[Feature #18980]: https://bugs.ruby-lang.org/issues/18980
377382
[Feature #18949]: https://bugs.ruby-lang.org/issues/18949
378383
[Bug #19012]: https://bugs.ruby-lang.org/issues/19012
379384
[Bug #19150]: https://bugs.ruby-lang.org/issues/19150

parse.y

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12785,6 +12785,11 @@ gettable(struct parser_params *p, ID id, const YYLTYPE *loc)
1278512785
}
1278612786
# endif
1278712787
/* method call without arguments */
12788+
if (dyna_in_block(p) && id == rb_intern("it")
12789+
&& !(DVARS_TERMINAL_P(p->lvtbl->args) || DVARS_TERMINAL_P(p->lvtbl->args->prev))
12790+
&& p->max_numparam != ORDINAL_PARAM) {
12791+
rb_warn0("`it` calls without arguments will refer to the first block param in Ruby 3.4; use it() or self.it");
12792+
}
1278812793
return NEW_VCALL(id, loc);
1278912794
case ID_GLOBAL:
1279012795
return NEW_GVAR(id, loc);

test/ruby/test_syntax.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,17 @@ def test_numbered_parameter
17191719
assert_valid_syntax("p { [_1 **2] }")
17201720
end
17211721

1722+
def test_it
1723+
assert_no_warning(/`it`/) {eval('if false; it; end')}
1724+
assert_no_warning(/`it`/) {eval('def foo; it; end')}
1725+
assert_warn(/`it`/) {eval('0.times { it }')}
1726+
assert_no_warning(/`it`/) {eval('0.times { || it }')}
1727+
assert_no_warning(/`it`/) {eval('0.times { |_n| it }')}
1728+
assert_warn(/`it`/) {eval('0.times { it; it = 1; it }')}
1729+
assert_no_warning(/`it`/) {eval('0.times { it = 1; it }')}
1730+
assert_no_warning(/`it`/) {eval('it = 1; 0.times { it }')}
1731+
end
1732+
17221733
def test_value_expr_in_condition
17231734
mesg = /void value expression/
17241735
assert_syntax_error("tap {a = (true ? next : break)}", mesg)

0 commit comments

Comments
 (0)