Project

General

Profile

Actions

Bug #11970

closed

Multiple Assignment Into a Hash with Destructuring causes segfault

Added by dwahl (Davis Wahl) over 8 years ago. Updated almost 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
[ruby-core:72777]

Description

Segfaults in 2.2.3 and 2.3.0, In 2.1.0 and below, produces {[:foo]=>:bar}

foo = [:foo]
bar = [:bar]

h = {}
h[*foo], _tail = *bar # Segfault

Using hash assignment/destructuring in this way may very well be undefined. I am surprised that the hash key h[*foo] destructures in later examples, but I'm not really sure what the behavior should be. A number of similar constructs
produce consistent behavior, which leads me to believe the above syntax should work (or at least not segfault).

Below examples produce the same output in ruby 1.9.3, 2.1.0, 2.2.3, and 2.3.0

h = {}
h[:foo], _tail = *bar
puts h
# => {:foo => :bar}

h = {}
h[foo[0]], _tail = *bar
puts h
# => {:foo => :bar}

h = {}
h[*foo] = :bar
puts h
# => {:foo => :bar}

Rubies Tested:

ruby 1.9.3p550 (2014-10-27 revision 48165) [x86_64-linux]
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]

Files

dump (12.4 KB) dump dwahl (Davis Wahl), 01/08/2016 06:19 PM

Updated by dwahl (Davis Wahl) over 8 years ago

I apologize for whatever I did to mangle the formatting.

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Description updated (diff)
  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED

Seems incorrect results also in 2.0 and 2.1.

Actions #4

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Status changed from Open to Closed

Applied in changeset r53495.


compile.c: fix lhs splat in massign

  • compile.c (compile_massign_lhs): when index ends with splat,
    append rhs value to it like POSTARG, since VM_CALL_ARGS_SPLAT
    splats the last argument only. [ruby-core:72777] [Bug #11970]

Updated by nagachika (Tomoyuki Chikanaga) about 8 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED, 2.3: DONE

ruby_2_3 r54478 merged revision(s) 53495.

Updated by usa (Usaku NAKAMURA) almost 8 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED, 2.3: DONE to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: DONE, 2.3: DONE

ruby_2_2 r54671 merged revision(s) 53495.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0