Project

General

Profile

Actions

Bug #20111

closed

`defined?` returns `expression` for assignment operators combined with fully qualified constants

Added by andrykonchin (Andrew Konchin) 11 months ago. Updated 9 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:115991]

Description

defined? doesn't consider &&=, ||= and other ...= operators as assignment:

defined?(A::B += 1) # => "expression"
defined?(A::B &&= true) # => "expression"
defined?(A::B ||= true) # => "expression"

But considers as assignment ordinal assignment:

defined?(A::B = 1) # => "assignment"

Wondering if it's expected behaviour.

Updated by Eregon (Benoit Daloze) 11 months ago

At least it seems inconsistent with defined?(A += 1) and defined?(a += 1) which are both "assignment"

Actions #2

Updated by andrykonchin (Andrew Konchin) 11 months ago

  • Description updated (diff)

Updated by jeremyevans0 (Jeremy Evans) 11 months ago

I submitted a pull request to fix this: https://github.com/ruby/ruby/pull/9476

Actions #4

Updated by jeremyevans (Jeremy Evans) 11 months ago

  • Status changed from Open to Closed

Applied in changeset git|ef751252711ca7ecabb3e4ad9214fa0d1d63608a.


Make defined? for op asgn expressions to constants use "assignment"

Previously, it used "expression", as that was the default. However,
op asgn expressions to constants use the NODE_OP_CDECL, so recognize
that node type as assignement.

Fixes [Bug #20111]

Updated by ko1 (Koichi Sasada) 9 months ago

Just curious, who cares the difference?

Updated by Eregon (Benoit Daloze) 9 months ago

@ko1 (Koichi Sasada) Just inconsistency discovered while implementing defined? for these various constructs.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like1Like0Like1