Project

General

Profile

Actions

Bug #20111

closed

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

Bug #20111: `defined?` returns `expression` for assignment operators combined with fully qualified constants

Added by andrykonchin (Andrew Konchin) almost 2 years ago. Updated over 1 year 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) almost 2 years ago Actions #1 [ruby-core:115992]

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

Updated by andrykonchin (Andrew Konchin) almost 2 years ago Actions #2

  • Description updated (diff)

Updated by jeremyevans (Jeremy Evans) almost 2 years ago Actions #4

  • 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) over 1 year ago Actions #5 [ruby-core:116716]

Just curious, who cares the difference?

Updated by Eregon (Benoit Daloze) over 1 year ago 1Actions #6 [ruby-core:116740]

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

Actions

Also available in: PDF Atom