Project

General

Profile

Actions

Bug #5449

closed

nested constant opasign not working

Added by rkh (Konstantin Haase) about 13 years ago. Updated almost 12 years ago.

Status:
Closed
Target version:
ruby -v:
1.9.2-p290
Backport:
[ruby-core:40154]

Description

=begin
This code works on 1.9:

Foo ||= 42

However, (({ ::Foo ||= 42 })) and
Foo ||= Module.new
Foo::Bar ||= 42

both raise a SyntaxError: constant re-assignment.

(Note: I had to use the (({...})) syntax so Redmine wouldn't turn ::Foo into a link)
=end


Files

parse.y.patch (481 Bytes) parse.y.patch technohippy (Yasushi ANDO), 10/19/2011 11:44 AM

Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Bug #6067: Conditional assignment of a nested constant raises a SyntaxErrorClosedmatz (Yukihiro Matsumoto)02/23/2012Actions

Updated by technohippy (Yasushi ANDO) about 13 years ago

I checked this just for my curiosity.

Foo ||= 42

does not work on ruby1.8,

::Foo = 42 # constant re-assignment
Foo = Foo || 42 # uninitialized constant

and these two statements raise exceptions on ruby1.9. IMHO, "Foo ||= 42" should raise an error on 1.9. I attached my poor patch for the purpose of reference.

Updated by ko1 (Koichi Sasada) over 12 years ago

  • Status changed from Open to Assigned
  • Assignee set to matz (Yukihiro Matsumoto)
  • Target version set to 2.0.0

Updated by ko1 (Koichi Sasada) over 12 years ago

  • Assignee changed from matz (Yukihiro Matsumoto) to nobu (Nobuyoshi Nakada)

matz said that it should not raise an error.

Actions #4

Updated by nobu (Nobuyoshi Nakada) almost 12 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r38585.
Konstantin, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


scoped constant op-assignment

  • node.h (NODE_OP_CDECL), compile.c (iseq_compile_each),
    parse.y (stmt, arg): allow scoped constant op-assignment.
    [ruby-core:40154] [Bug #5449]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0