Project

General

Profile

Bug #5449

nested constant opasign not working

Added by Konstantin Haase about 5 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Normal
ruby -v:
1.9.2-p290
[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

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


Related issues

Duplicated by Ruby trunk - Bug #6067: Conditional assignment of a nested constant raises a SyntaxError Closed 02/23/2012

Associated revisions

Revision 38585
Added by Nobuyoshi Nakada almost 4 years ago

scoped constant op-assignment

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

Revision 38585
Added by Nobuyoshi Nakada almost 4 years ago

scoped constant op-assignment

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

Revision 38585
Added by Nobuyoshi Nakada almost 4 years ago

scoped constant op-assignment

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

Revision 38586
Added by Nobuyoshi Nakada almost 4 years ago

scoped constant op-assignment

  • test/ripper/test_parser_events.rb (test_opassign_error): allow scoped constant op-assignment. [Bug #5449]

Revision 38586
Added by Nobuyoshi Nakada almost 4 years ago

scoped constant op-assignment

  • test/ripper/test_parser_events.rb (test_opassign_error): allow scoped constant op-assignment. [Bug #5449]

Revision 38586
Added by Nobuyoshi Nakada almost 4 years ago

scoped constant op-assignment

  • test/ripper/test_parser_events.rb (test_opassign_error): allow scoped constant op-assignment. [Bug #5449]

Revision 38587
Added by Nobuyoshi Nakada almost 4 years ago

scoped constant op-assignment

  • test/ripper/test_parser_events.rb (test_opassign): allow scoped
    constant op-assignment. [Bug #5449]

  • test/ripper/test_parser_events.rb (test_opassign_error): backref
    opassign is only error.

Revision 38587
Added by Nobuyoshi Nakada almost 4 years ago

scoped constant op-assignment

  • test/ripper/test_parser_events.rb (test_opassign): allow scoped
    constant op-assignment. [Bug #5449]

  • test/ripper/test_parser_events.rb (test_opassign_error): backref
    opassign is only error.

Revision 38587
Added by Nobuyoshi Nakada almost 4 years ago

scoped constant op-assignment

  • test/ripper/test_parser_events.rb (test_opassign): allow scoped
    constant op-assignment. [Bug #5449]

  • test/ripper/test_parser_events.rb (test_opassign_error): backref
    opassign is only error.

History

#1 [ruby-core:40224] Updated by Yasushi ANDO about 5 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.

#2 [ruby-core:43192] Updated by Koichi Sasada almost 5 years ago

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

#3 [ruby-core:46418] Updated by Koichi Sasada over 4 years ago

  • Assignee changed from Yukihiro Matsumoto to Nobuyoshi Nakada

matz said that it should not raise an error.

#4 Updated by Nobuyoshi Nakada almost 4 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. [Bug #5449]

Also available in: Atom PDF