Project

General

Profile

Bug #6067

Conditional assignment of a nested constant raises a SyntaxError

Added by brixen (Brian Shirai) over 7 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin10.8.0]
Backport:
[ruby-core:42826]

Description

I can conditionally assign a simple constant:

$ ruby -v -e 'p X ||= 1'
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin10.8.0]
1

However, conditional assignment of a nested constant raises a SyntaxError:

$ ruby -v -e 'module A; end; p A::X ||= 1'
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin10.8.0]
-e:1: constant re-assignment

But I can assign the constant unconditionally, of course:

$ ruby -v -e 'module A; end; p A::X = 1'
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin10.8.0]
1

Is this a bug?

Thanks,
Brian


Related issues

Is duplicate of Ruby master - Bug #5449: nested constant opasign not workingClosed10/15/2011Actions

History

Updated by steakknife (Barry Allard) over 7 years ago

One would think it would evaluate similar to:

(A::X = 1 if ! defined? A::X or A::X.nil? ; A::X)

For comparison, these also fail:

ruby -e 'module A; end; p A::X = 2; p A::X ||= 1'
ruby -e 'module B module Inner end end; B::Inner::X ||= 4; p B::Inner::X'

Also, these correctly succeed:

ruby -e 'module F X ||= 2 end; p F::X'
ruby -e 'module G class Foo; X ||= 3 end end; p G::Foo::X'
ruby -e 'module H module Inner end end; H::Inner::X = 4; p H::Inner::X'
#2

Updated by ko1 (Koichi Sasada) over 7 years ago

  • Assignee set to matz (Yukihiro Matsumoto)
#3

Updated by shyouhei (Shyouhei Urabe) over 7 years ago

  • Status changed from Open to Assigned

Updated by nahi (Hiroshi Nakamura) over 7 years ago

Closing as a duplicate, since #5449 was confirmed as a bug by Matz. #5449 will fix it.

Updated by nahi (Hiroshi Nakamura) over 7 years ago

  • Status changed from Assigned to Closed

Also available in: Atom PDF