Skip to content

Arrays duplicated by splats (e.g. a_dup = [*a]) share structure, but shouldn't #1118

@gamache

Description

@gamache

I've often seen the idiom a_dup = [*a] to duplicate arrays. JRuby seems to optimize [*a] to a, which results in a and a_dup pointing to the same array object. Awkward!

a = [1, 2, 3]
a_dup = [*a]
a << 4 # => [1, 2, 3, 4]
a_dup # => [1, 2, 3, 4]             ### a_dup should not have been mutated!

This bug appears in at least JRuby 1.7.4 to present. It does not appear in MRI.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions