From: "tompng (tomoya ishida) via ruby-core" Date: 2025-02-13T16:55:36+00:00 Subject: [ruby-core:120986] [Ruby master Bug#21117] Inconsistent behaviour between "_1" and "it" variables Issue #21117 has been updated by tompng (tomoya ishida). Status changed from Open to Assigned Assignee set to prism These two should be SyntaxError, and is actually SyntaxError with --parser=parse.y ~~~ruby [1, 2, 3].each { _1 += 1; p _1 } [1, 2, 3].map { _1 += 1 } ~~~ Some difference between `it` and `_1` is by design, but the inconsistencies raised in this issue are caused by difference between parse.y and Prism and should be fixed. ---------------------------------------- Bug #21117: Inconsistent behaviour between "_1" and "it" variables https://bugs.ruby-lang.org/issues/21117#change-111890 * Author: radarek (Rados��aw Bu��at) * Status: Assigned * Assignee: prism * ruby -v: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [arm64-darwin24] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- I believe variables `_1` and `it` should have consistent behaviour and the same as normal local variables. Here are inconsistencies: ```ruby # 1. Assigning new value [1, 2, 3].each { |v| v = v + 1; p v } # works as expected [1, 2, 3].each { it = it + 1; p it } # works as expected [1, 2, 3].each { _1 = _1 + 1; p _1 } # SyntaxError # 2. Using operators like += on them [1, 2, 3].each { |v| v += 1; p v } # works as expected [1, 2, 3].each { it += 1; p it } # SyntaxError but I expected it to work correctly after 1st point [1, 2, 3].each { _1 += 1; p _1 } # works, which is inconsistent with 1 point # however, this one does not work [1, 2, 3].map { _1 += 1 } # runtime error is raised: undefined method '+' for nil (NoMethodError) ``` If both `_1` and `it` are advertised as block local variables then I would expect that overwriting works correctly, both using expressions like `_1 = _1 + 1` and `_1 *= 2`. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/