Project

General

Profile

Actions

Bug #21139

open

Prism and parse.y parses `it = it` differently

Added by tompng (tomoya ishida) about 1 month ago. Updated 3 days ago.

Status:
Assigned
Assignee:
Target version:
-
ruby -v:
ruby 3.5.0dev (2025-02-14T16:49:52Z master ee181d1bb7) +PRISM [x86_64-linux]
[ruby-core:121054]

Description

# ruby --parser=parse.y -e "42.tap { it = it; p it }"
nil
# ruby --parser=prism -e "42.tap { it = it; p it }"
42

Files

clipboard-202503081702-idzz2.png (22.6 KB) clipboard-202503081702-idzz2.png alanwu (Alan Wu), 03/08/2025 10:02 PM

Related issues 2 (0 open2 closed)

Related to Ruby - Bug #21137: Compound assignment operator with "it" parsed differently between parse.y and prismClosedprismActions
Related to Ruby - Bug #21138: The modifier expression with "it" is parsed differently in parse.y and Prism, which is unexpected in both.ClosedprismActions

Updated by matz (Yukihiro Matsumoto) about 1 month ago

Assignment to it should be prohibited in the long run. Temporarily, I vote for Prism behavior.

Matz.

By the way, how can I clear assignee of the issue on Redmine?

Updated by nobu (Nobuyoshi Nakada) about 1 month ago

matz (Yukihiro Matsumoto) wrote in #note-1:

Assignment to it should be prohibited in the long run. Temporarily, I vote for Prism behavior.

  1. Currently, it is an ordinary local variable if assigned syntactically.
  2. And a local variable is nil before assigned, even in its RHS, at the runtime.

The behavior in parse.y obeys above principles.

Do you want to change the rule 1, make it always special?

Actions #3

Updated by nobu (Nobuyoshi Nakada) about 1 month ago

  • Related to Bug #21137: Compound assignment operator with "it" parsed differently between parse.y and prism added
Actions #4

Updated by nobu (Nobuyoshi Nakada) about 1 month ago

  • Related to Bug #21138: The modifier expression with "it" is parsed differently in parse.y and Prism, which is unexpected in both. added

Updated by alanwu (Alan Wu) 21 days ago

matz (Yukihiro Matsumoto) wrote in #note-1:

By the way, how can I clear assignee of the issue on Redmine?

The null option in the menu is the very first one and is rendered with a tiny height to make it hard to mouse over. It's easier to pick it with arrow keys.
Maybe the UX could be improved by tweaking some settings? CC @hsbt (Hiroshi SHIBATA)

Updated by matz (Yukihiro Matsumoto) 16 days ago

I said I prefer Prism behavior to parse.y. But It was due to my misunderstanding. it = it should initialize the local variable named it and the value should be nil, just like other x = x assignment in Ruby.
In the future, all assignment to it could be prohibited, maybe.

Matz.

Updated by kddnewton (Kevin Newton) 16 days ago

  • Assignee set to prism
Actions #8

Updated by hsbt (Hiroshi SHIBATA) 3 days ago

  • Status changed from Open to Assigned
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0