Project

General

Profile

Actions

Bug #12291

closed

Struct member accessor is not consistent with hash access when keys are repeated

Added by jcole1989 (James Coleman) over 8 years ago. Updated over 8 years ago.

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

Description

irb(main):001:0> foo = Struct.new(:a, :a).new("1", "2")
=> #<struct a="1", a="2">
irb(main):002:0> foo.a
=> "2"
irb(main):003:0> foo['a']
=> "1"
irb(main):004:0> foo.members
=> [:a, :a]
irb(main):005:0> foo.to_h
=> {:a=>"2"}

Updated by jcole1989 (James Coleman) over 8 years ago

I would expect that foo['a'] and foo.a to return the same value.

Updated by jkrmr (Jake Romer) over 8 years ago

Interestingly, I'm seeing the following on ruby 2.0.0p648:

[1] pry(main)> foo = Struct.new(:a, :a).new("1", "2")
=> #<struct  a="1", a="1">

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED
Actions #4

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Status changed from Open to Closed

Applied in changeset r54612.


struct.c: unique members

  • struct.c (struct_make_members_list, rb_struct_s_def): member
    names should be unique. [ruby-core:74971] [Bug #12291]

Updated by naruse (Yui NARUSE) over 8 years ago

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

ruby_2_3 r54637 merged revision(s) 54611,54612.

Updated by usa (Usaku NAKAMURA) over 8 years ago

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

ruby_2_2 r54685 merged revision(s) 54611,54612.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0