Project

General

Profile

Backport #5124

foo = [*bar] implies foo.equal?(bar)

Added by adgar (Michael Edgar) over 7 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
[ruby-core:38625]

Description

I just ran into this as a result of some slightly sloppy coding, but it did disagree with my internal assumptions.

Normally, I expect the Array literal syntax to create a new object, every time. So when I rewrote some code and ended up with something similar to the following, my tests broke, and I'm not sure that's how it should be. Here's the reduced test case:

some_ary = [1, 2, 3]
bar = [*some_ary]
bar << 4

p bar

[1, 2, 3, 4]
p some_ary
[1, 2, 3, 4]

I see it's clearly taking an opportunity for optimization, so I'm more than happy to hear that as a reason for rejecting this. It does warrant documentation somewhere, though, I'd say. Not sure where that documentation would go.


Related issues

Is duplicate of Ruby trunk - Feature #1125: [*x] (array consisting only of a splat) does not necessarily return a new arrayClosed2009-02-07

Associated revisions

Revision f52f0339
Added by naruse (Yui NARUSE) over 6 years ago

merge revision(s) 34633: [Backport #5124]

* insns.def (splatarray): make new array if flag is set.

* compile.c (iseq_compile_each): make new array with
  splat. [Feature #1125]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@36228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 36228
Added by naruse (Yui NARUSE) over 6 years ago

merge revision(s) 34633: [Backport #5124]

* insns.def (splatarray): make new array if flag is set.

* compile.c (iseq_compile_each): make new array with
  splat. [Feature #1125]

History

#1 [ruby-core:38626] Updated by nobu (Nobuyoshi Nakada) over 7 years ago

  • Category set to core
  • Status changed from Open to Assigned
  • Assignee set to ko1 (Koichi Sasada)
  • Target version set to 1.9.3

It's easy to fix that splatarray always makes a new array, but I'm uncertain of its flag.

#2 [ruby-core:39033] Updated by kosaki (Motohiro KOSAKI) over 7 years ago

Sasada-san, ping?

#3 [ruby-core:39073] Updated by ko1 (Koichi Sasada) about 7 years ago

  • ruby -v changed from ruby 1.9.2p188 (2011-03-28 revision 31204) [x86_64-darwin10.7.0] to -

Hi,

Sorry for late response.

(2011/07/31 6:48), Nobuyoshi Nakada wrote:

It's easy to fix that splatarray always makes a new array, but I'm uncertain of its flag.

Could you apply your patch if there is no failure on test-all/ruby-spec?

--
// SASADA Koichi at atdot dot net

#4 [ruby-core:45855] Updated by ko1 (Koichi Sasada) over 6 years ago

  • Status changed from Assigned to Feedback

nobu: ping.

#5 Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby trunk to Backport193
  • Category deleted (core)
  • Target version deleted (1.9.3)

#6 [ruby-core:45876] Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Status changed from Feedback to Assigned
  • Assignee changed from ko1 (Koichi Sasada) to naruse (Yui NARUSE)

#7 Updated by naruse (Yui NARUSE) over 6 years ago

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

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


merge revision(s) 34633: [Backport #5124]

* insns.def (splatarray): make new array if flag is set.

* compile.c (iseq_compile_each): make new array with
  splat. [Feature #1125]

Also available in: Atom PDF