From 6f6793e5b900e7a924fbae9da4ca5d6d41ab6241 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Mon, 3 Mar 2025 19:14:34 +0200 Subject: [PATCH 1/5] Add missing specs for Data class --- spec/ruby/core/data/deconstruct_keys_spec.rb | 107 ++++++++++++++++++ spec/ruby/core/data/deconstruct_spec.rb | 10 ++ spec/ruby/core/data/eql_spec.rb | 65 +++++++++++ spec/ruby/core/data/equal_value_spec.rb | 65 +++++++++++ spec/ruby/core/data/fixtures/classes.rb | 6 + spec/ruby/core/data/hash_spec.rb | 27 +++++ spec/ruby/core/data/inspect_spec.rb | 8 ++ spec/ruby/core/data/shared/inspect.rb | 54 +++++++++ spec/ruby/core/data/to_s_spec.rb | 8 ++ spec/tags/core/data/deconstruct_keys_tags.txt | 2 + spec/tags/core/data/inspect_tags.txt | 1 + spec/tags/core/data/to_s_tags.txt | 1 + 12 files changed, 354 insertions(+) create mode 100644 spec/ruby/core/data/deconstruct_keys_spec.rb create mode 100644 spec/ruby/core/data/deconstruct_spec.rb create mode 100644 spec/ruby/core/data/eql_spec.rb create mode 100644 spec/ruby/core/data/equal_value_spec.rb create mode 100644 spec/ruby/core/data/hash_spec.rb create mode 100644 spec/ruby/core/data/inspect_spec.rb create mode 100644 spec/ruby/core/data/shared/inspect.rb create mode 100644 spec/ruby/core/data/to_s_spec.rb create mode 100644 spec/tags/core/data/deconstruct_keys_tags.txt create mode 100644 spec/tags/core/data/inspect_tags.txt create mode 100644 spec/tags/core/data/to_s_tags.txt diff --git a/spec/ruby/core/data/deconstruct_keys_spec.rb b/spec/ruby/core/data/deconstruct_keys_spec.rb new file mode 100644 index 000000000000..07af87771d8d --- /dev/null +++ b/spec/ruby/core/data/deconstruct_keys_spec.rb @@ -0,0 +1,107 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +ruby_version_is "3.2" do + describe "Data#deconstruct" do + it "returns a hash of attributes" do + klass = Data.define(:x, :y) + d = klass.new(1, 2) + d.deconstruct_keys([:x, :y]).should == {x: 1, y: 2} + end + + it "requires one argument" do + klass = Data.define(:x, :y) + d = klass.new(1, 2) + + -> { + d.deconstruct_keys + }.should raise_error(ArgumentError, /wrong number of arguments \(given 0, expected 1\)/) + end + + it "returns only specified keys" do + klass = Data.define(:x, :y) + d = klass.new(1, 2) + + d.deconstruct_keys([:x, :y]).should == {x: 1, y: 2} + d.deconstruct_keys([:x] ).should == {x: 1} + d.deconstruct_keys([] ).should == {} + end + + it "accepts string attribute names" do + klass = Data.define(:x, :y) + d = klass.new(1, 2) + d.deconstruct_keys(['x', 'y']).should == {'x' => 1, 'y' => 2} + end + + it "accepts argument position number as well but returns them as keys" do + klass = Data.define(:x, :y) + d = klass.new(1, 2) + + d.deconstruct_keys([0, 1]).should == {0 => 1, 1 => 2} + d.deconstruct_keys([0] ).should == {0 => 1} + d.deconstruct_keys([-1] ).should == {-1 => 2} + end + + it "ignores incorrect position numbers" do + klass = Data.define(:x, :y) + d = klass.new(1, 2) + + d.deconstruct_keys([0, 3]).should == {0 => 1} + end + + it "support mixing attribute names and argument position numbers" do + klass = Data.define(:x, :y) + d = klass.new(1, 2) + + d.deconstruct_keys([0, :x]).should == {0 => 1, :x => 1} + end + + it "returns an empty hash when there are more keys than attributes" do + klass = Data.define(:x, :y) + d = klass.new(1, 2) + d.deconstruct_keys([:x, :y, :x]).should == {} + end + + it "returns at first not existing attribute name" do + klass = Data.define(:x, :y) + d = klass.new(1, 2) + + d.deconstruct_keys([:a, :x]).should == {} + d.deconstruct_keys([:x, :a]).should == {x: 1} + end + + it "returns at first not existing argument position number" do + klass = Data.define(:x, :y) + d = klass.new(1, 2) + + d.deconstruct_keys([3, 0]).should == {} + d.deconstruct_keys([0, 3]).should == {0 => 1} + end + + it "accepts nil argument and return all the attributes" do + klass = Data.define(:x, :y) + d = klass.new(1, 2) + + d.deconstruct_keys(nil).should == {x: 1, y: 2} + end + + it "raises TypeError if index is not a String, a Symbol and not convertible to Integer " do + klass = Data.define(:x, :y) + d = klass.new(1, 2) + + -> { + d.deconstruct_keys([0, []]) + }.should raise_error(TypeError, "no implicit conversion of Array into Integer") + end + + it "raise TypeError if passed anything except nil or array" do + klass = Data.define(:x, :y) + d = klass.new(1, 2) + + -> { d.deconstruct_keys('x') }.should raise_error(TypeError, /expected Array or nil/) + -> { d.deconstruct_keys(1) }.should raise_error(TypeError, /expected Array or nil/) + -> { d.deconstruct_keys(:x) }.should raise_error(TypeError, /expected Array or nil/) + -> { d.deconstruct_keys({}) }.should raise_error(TypeError, /expected Array or nil/) + end + end +end diff --git a/spec/ruby/core/data/deconstruct_spec.rb b/spec/ruby/core/data/deconstruct_spec.rb new file mode 100644 index 000000000000..00e938480624 --- /dev/null +++ b/spec/ruby/core/data/deconstruct_spec.rb @@ -0,0 +1,10 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +ruby_version_is "3.2" do + describe "Data#deconstruct" do + it "returns an array of attribute values" do + DataSpecs::Measure.new(42, "km").deconstruct.should == [42, "km"] + end + end +end \ No newline at end of file diff --git a/spec/ruby/core/data/eql_spec.rb b/spec/ruby/core/data/eql_spec.rb new file mode 100644 index 000000000000..906e46316cf7 --- /dev/null +++ b/spec/ruby/core/data/eql_spec.rb @@ -0,0 +1,65 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +ruby_version_is "3.2" do + describe "Data#eql?" do + it "returns true if the other is the same object" do + a = DataSpecs::Measure.new(42, "km") + a.should.eql?(a) + end + + it "returns true if the other has all the same fields" do + a = DataSpecs::Measure.new(42, "km") + b = DataSpecs::Measure.new(42, "km") + a.should.eql?(b) + end + + it "returns false if the other is a different object or has different fields" do + a = DataSpecs::Measure.new(42, "km") + b = DataSpecs::Measure.new(42, "mi") + a.should_not.eql?(b) + end + + it "returns false if other is of a different class" do + a = DataSpecs::Measure.new(42, "km") + klass = Data.define(*DataSpecs::Measure.members) + b = klass.new(42, "km") + a.should_not.eql?(b) + end + + it "returns false if any corresponding elements are not equal with #eql?" do + a = DataSpecs::Measure.new(42, "km") + b = DataSpecs::Measure.new(42.0, "mi") + a.should_not.eql?(b) + end + + context "recursive structure" do + it "returns true the other is the same object" do + a = DataSpecs::Measure.allocate + a.send(:initialize, amount: 42, unit: a) + + a.should.eql?(a) + end + + it "returns true if the other has all the same fields" do + a = DataSpecs::Measure.allocate + a.send(:initialize, amount: 42, unit: a) + + b = DataSpecs::Measure.allocate + b.send(:initialize, amount: 42, unit: b) + + a.should.eql?(b) + end + + it "returns false if any corresponding elements are not equal with #eql?" do + a = DataSpecs::Measure.allocate + a.send(:initialize, amount: a, unit: "km") + + b = DataSpecs::Measure.allocate + b.send(:initialize, amount: b, unit: "mi") + + a.should_not.eql?(b) + end + end + end +end diff --git a/spec/ruby/core/data/equal_value_spec.rb b/spec/ruby/core/data/equal_value_spec.rb new file mode 100644 index 000000000000..f90a7d7a62c4 --- /dev/null +++ b/spec/ruby/core/data/equal_value_spec.rb @@ -0,0 +1,65 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +ruby_version_is "3.2" do + describe "Data#==" do + it "returns true if the other is the same object" do + a = DataSpecs::Measure.new(42, "km") + a.should == a + end + + it "returns true if the other has all the same fields" do + a = DataSpecs::Measure.new(42, "km") + b = DataSpecs::Measure.new(42, "km") + a.should == b + end + + it "returns false if the other is a different object or has different fields" do + a = DataSpecs::Measure.new(42, "km") + b = DataSpecs::Measure.new(42, "mi") + a.should_not == b + end + + it "returns false if other is of a different class" do + a = DataSpecs::Measure.new(42, "km") + klass = Data.define(*DataSpecs::Measure.members) + b = klass.new(42, "km") + a.should_not == b + end + + it "returns false if any corresponding elements are not equal with #==" do + a = DataSpecs::Measure.new(42, "km") + b = DataSpecs::Measure.new(42.0, "mi") + a.should_not == b + end + + context "recursive structure" do + it "returns true the other is the same object" do + a = DataSpecs::Measure.allocate + a.send(:initialize, amount: 42, unit: a) + + a.should == a + end + + it "returns true if the other has all the same fields" do + a = DataSpecs::Measure.allocate + a.send(:initialize, amount: 42, unit: a) + + b = DataSpecs::Measure.allocate + b.send(:initialize, amount: 42, unit: b) + + a.should == b + end + + it "returns false if any corresponding elements are not equal with #==" do + a = DataSpecs::Measure.allocate + a.send(:initialize, amount: a, unit: "km") + + b = DataSpecs::Measure.allocate + b.send(:initialize, amount: b, unit: "mi") + + a.should_not == b + end + end + end +end diff --git a/spec/ruby/core/data/fixtures/classes.rb b/spec/ruby/core/data/fixtures/classes.rb index a5b0f4578f6c..6f4830360abc 100644 --- a/spec/ruby/core/data/fixtures/classes.rb +++ b/spec/ruby/core/data/fixtures/classes.rb @@ -2,6 +2,12 @@ module DataSpecs guard -> { ruby_version_is "3.2" and Data.respond_to?(:define) } do Measure = Data.define(:amount, :unit) + class MeasureWithOverriddenName < Measure + def self.name + "A" + end + end + class DataSubclass < Data; end end end diff --git a/spec/ruby/core/data/hash_spec.rb b/spec/ruby/core/data/hash_spec.rb new file mode 100644 index 000000000000..324a2abca4e9 --- /dev/null +++ b/spec/ruby/core/data/hash_spec.rb @@ -0,0 +1,27 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +ruby_version_is "3.2" do + describe "Data#hash" do + it "returns the same integer for objects with the same content" do + a = DataSpecs::Measure.new(42, "km") + b = DataSpecs::Measure.new(42, "km") + a.hash.should == b.hash + a.hash.should be_an_instance_of(Integer) + end + + it "returns different hashes for objects with different values" do + a = DataSpecs::Measure.new(42, "km") + b = DataSpecs::Measure.new(42, "ml") + a.hash.should_not == b.hash + + a = DataSpecs::Measure.new(42, "km") + b = DataSpecs::Measure.new(13, "km") + a.hash.should_not == b.hash + end + + it "returns different hashes for different classes" do + Data.define(:x).new(1).hash.should != Data.define(:x).new(1).hash + end + end +end diff --git a/spec/ruby/core/data/inspect_spec.rb b/spec/ruby/core/data/inspect_spec.rb new file mode 100644 index 000000000000..be823389205c --- /dev/null +++ b/spec/ruby/core/data/inspect_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require_relative 'shared/inspect' + +ruby_version_is "3.2" do + describe "Data#inspect" do + it_behaves_like :data_inspect, :inspect + end +end \ No newline at end of file diff --git a/spec/ruby/core/data/shared/inspect.rb b/spec/ruby/core/data/shared/inspect.rb new file mode 100644 index 000000000000..4c861df70bfa --- /dev/null +++ b/spec/ruby/core/data/shared/inspect.rb @@ -0,0 +1,54 @@ +require_relative '../fixtures/classes' + +describe :data_inspect, shared: true do + it "returns a string representation showing members and values" do + a = DataSpecs::Measure.new(42, "km") + a.send(@method).should == '#' + end + + it "returns a string representation without the class name for anonymous structs" do + Data.define(:a).new("").send(@method).should == '#' + end + + it "returns a string representation without the class name for structs nested in anonymous classes" do + c = Class.new + c.class_eval <<~DOC + Foo = Data.define(:a) + DOC + + c::Foo.new("").send(@method).should == '#' + end + + it "returns a string representation without the class name for structs nested in anonymous modules" do + m = Module.new + m.class_eval <<~DOC + Foo = Data.define(:a) + DOC + + m::Foo.new("").send(@method).should == '#' + end + + it "does not call #name method" do + struct = DataSpecs::MeasureWithOverriddenName.new(42, "km") + struct.send(@method).should == '#' + end + + it "does not call #name method when struct is anonymous" do + klass = Class.new(DataSpecs::Measure) do + def self.name + "A" + end + end + struct = klass.new(42, "km") + struct.send(@method).should == '#' + end + + context "recursive structure" do + it "returns string representation with recursive attribute replaced with ..." do + a = DataSpecs::Measure.allocate + a.send(:initialize, amount: 42, unit: a) + + a.send(@method).should == "#>" + end + end +end \ No newline at end of file diff --git a/spec/ruby/core/data/to_s_spec.rb b/spec/ruby/core/data/to_s_spec.rb new file mode 100644 index 000000000000..0b9099f03564 --- /dev/null +++ b/spec/ruby/core/data/to_s_spec.rb @@ -0,0 +1,8 @@ +require_relative '../../spec_helper' +require_relative 'shared/inspect' + +ruby_version_is "3.2" do + describe "Data#to_s" do + it_behaves_like :data_inspect, :to_s + end +end diff --git a/spec/tags/core/data/deconstruct_keys_tags.txt b/spec/tags/core/data/deconstruct_keys_tags.txt new file mode 100644 index 000000000000..229e5c721372 --- /dev/null +++ b/spec/tags/core/data/deconstruct_keys_tags.txt @@ -0,0 +1,2 @@ +fails:Data#deconstruct accepts argument position number as well but returns them as keys +fails:Data#deconstruct ignores incorrect position numbers diff --git a/spec/tags/core/data/inspect_tags.txt b/spec/tags/core/data/inspect_tags.txt new file mode 100644 index 000000000000..52be11af3f15 --- /dev/null +++ b/spec/tags/core/data/inspect_tags.txt @@ -0,0 +1 @@ +fails:Data#inspect recursive structure returns string representation with recursive attribute replaced with ... diff --git a/spec/tags/core/data/to_s_tags.txt b/spec/tags/core/data/to_s_tags.txt new file mode 100644 index 000000000000..99bf0f849402 --- /dev/null +++ b/spec/tags/core/data/to_s_tags.txt @@ -0,0 +1 @@ +fails:Data#to_s recursive structure returns string representation with recursive attribute replaced with ... From 3f8a98998af0d50db467e46ce7d25b0b61c8b5ec Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Mon, 3 Mar 2025 19:30:42 +0200 Subject: [PATCH 2/5] Add missing specs for Struct class --- .../ruby/core/struct/deconstruct_keys_spec.rb | 25 +++++++++++++++++++ .../core/struct/deconstruct_keys_tags.txt | 2 ++ 2 files changed, 27 insertions(+) create mode 100644 spec/tags/core/struct/deconstruct_keys_tags.txt diff --git a/spec/ruby/core/struct/deconstruct_keys_spec.rb b/spec/ruby/core/struct/deconstruct_keys_spec.rb index b4c84c49dfa3..cd05aee05679 100644 --- a/spec/ruby/core/struct/deconstruct_keys_spec.rb +++ b/spec/ruby/core/struct/deconstruct_keys_spec.rb @@ -40,6 +40,14 @@ s.deconstruct_keys([0, 1, 2]).should == {0 => 10, 1 => 20, 2 => 30} s.deconstruct_keys([0, 1] ).should == {0 => 10, 1 => 20} s.deconstruct_keys([0] ).should == {0 => 10} + s.deconstruct_keys([-1] ).should == {-1 => 30} + end + + it "support mixing attribute names and argument position numbers" do + struct = Struct.new(:x, :y) + s = struct.new(1, 2) + + s.deconstruct_keys([0, :x]).should == {0 => 1, :x => 1} end it "returns an empty hash when there are more keys than attributes" do @@ -57,6 +65,14 @@ s.deconstruct_keys([:x, :a]).should == {x: 1} end + it "returns at first not existing argument position number" do + struct = Struct.new(:x, :y) + s = struct.new(1, 2) + + s.deconstruct_keys([3, 0]).should == {} + s.deconstruct_keys([0, 3]).should == {0 => 1} + end + it "accepts nil argument and return all the attributes" do struct = Struct.new(:x, :y) obj = struct.new(1, 2) @@ -64,6 +80,15 @@ obj.deconstruct_keys(nil).should == {x: 1, y: 2} end + it "raises TypeError if index is not a String, a Symbol and not convertible to Integer " do + struct = Struct.new(:x, :y) + s = struct.new(1, 2) + + -> { + s.deconstruct_keys([0, []]) + }.should raise_error(TypeError, "no implicit conversion of Array into Integer") + end + it "raise TypeError if passed anything except nil or array" do struct = Struct.new(:x, :y) s = struct.new(1, 2) diff --git a/spec/tags/core/struct/deconstruct_keys_tags.txt b/spec/tags/core/struct/deconstruct_keys_tags.txt new file mode 100644 index 000000000000..cc4cbfa6814d --- /dev/null +++ b/spec/tags/core/struct/deconstruct_keys_tags.txt @@ -0,0 +1,2 @@ +fails:Struct#deconstruct_keys returns at first not existing argument position number +fails:Struct#deconstruct_keys raises TypeError if index is not a String, a Symbol and not convertible to Integer From 4530f82d2814938413d3f43c77b871bc61a98a17 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Mon, 3 Mar 2025 20:12:32 +0200 Subject: [PATCH 3/5] Fix specs for Struct --- .../core/struct/deconstruct_keys_tags.txt | 2 -- src/main/ruby/truffleruby/core/struct.rb | 23 +++++++++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) delete mode 100644 spec/tags/core/struct/deconstruct_keys_tags.txt diff --git a/spec/tags/core/struct/deconstruct_keys_tags.txt b/spec/tags/core/struct/deconstruct_keys_tags.txt deleted file mode 100644 index cc4cbfa6814d..000000000000 --- a/spec/tags/core/struct/deconstruct_keys_tags.txt +++ /dev/null @@ -1,2 +0,0 @@ -fails:Struct#deconstruct_keys returns at first not existing argument position number -fails:Struct#deconstruct_keys raises TypeError if index is not a String, a Symbol and not convertible to Integer diff --git a/src/main/ruby/truffleruby/core/struct.rb b/src/main/ruby/truffleruby/core/struct.rb index db7b9058103c..a5e4a4a45b83 100644 --- a/src/main/ruby/truffleruby/core/struct.rb +++ b/src/main/ruby/truffleruby/core/struct.rb @@ -223,7 +223,7 @@ def [](var) when String var = var.to_sym else - var = check_index_var(var) + var = check_index_var!(var) end unless _attrs.include? var.to_sym @@ -245,15 +245,15 @@ def []=(var, obj) raise NameError, "no member '#{var}' in struct" end else - var = check_index_var(var) + var = check_index_var!(var) end Primitive.check_frozen self Primitive.object_hidden_var_set(self, var, obj) end - private def check_index_var(var) - var = Integer(var) + private def check_index_var!(var) + var = Truffle::Type.rb_convert_type(var, Integer, :to_int) a_len = _attrs.length if var >= a_len raise IndexError, "offset #{var} too large for struct(size:#{a_len})" @@ -263,6 +263,15 @@ def []=(var, obj) _attrs[var] end + private def check_index_var(var) + var = Truffle::Type.rb_convert_type(var, Integer, :to_int) + a_len = _attrs.length + + if var < a_len && var >= -a_len + _attrs[var] + end + end + def dig(key, *more) result = read_or_nil(key) if Primitive.nil?(result) || more.empty? @@ -347,7 +356,7 @@ def deconstruct_keys(keys) symbolized_key = check_index_var(requested_key) end - if _attrs.include?(symbolized_key) + if symbolized_key && _attrs.include?(symbolized_key) h[requested_key] = Primitive.object_hidden_var_get(self, symbolized_key) else return h @@ -369,14 +378,14 @@ def values_at(*args) finish_in_bounds = [finish, _attrs.length - 1].min start.upto(finish_in_bounds) do |index| - name = check_index_var(index) + name = check_index_var!(index) out << Primitive.object_hidden_var_get(self, name) end (finish_in_bounds + 1).upto(finish) { out << nil } else index = Primitive.rb_num2int(elem) - name = check_index_var(index) + name = check_index_var!(index) out << Primitive.object_hidden_var_get(self, name) end end From 75b3bcbd8910021400604d17e38293cefdc4d19d Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Mon, 3 Mar 2025 20:29:28 +0200 Subject: [PATCH 4/5] Fix specs for Data --- spec/tags/core/data/deconstruct_keys_tags.txt | 2 -- src/main/ruby/truffleruby/core/data.rb | 6 +++++- 2 files changed, 5 insertions(+), 3 deletions(-) delete mode 100644 spec/tags/core/data/deconstruct_keys_tags.txt diff --git a/spec/tags/core/data/deconstruct_keys_tags.txt b/spec/tags/core/data/deconstruct_keys_tags.txt deleted file mode 100644 index 229e5c721372..000000000000 --- a/spec/tags/core/data/deconstruct_keys_tags.txt +++ /dev/null @@ -1,2 +0,0 @@ -fails:Data#deconstruct accepts argument position number as well but returns them as keys -fails:Data#deconstruct ignores incorrect position numbers diff --git a/src/main/ruby/truffleruby/core/data.rb b/src/main/ruby/truffleruby/core/data.rb index 14bba32c089b..7dd206c022ed 100644 --- a/src/main/ruby/truffleruby/core/data.rb +++ b/src/main/ruby/truffleruby/core/data.rb @@ -166,15 +166,19 @@ def deconstruct_keys(keys) return {} if members_hash.size < keys.size h = {} + members = Primitive.class(self)::CLASS_MEMBERS keys.each do |requested_key| case requested_key when Symbol symbolized_key = requested_key when String symbolized_key = requested_key.to_sym + else + index = Truffle::Type.rb_convert_type(requested_key, Integer, :to_int) + symbolized_key = members[index] end - if members_hash.include?(symbolized_key) + if symbolized_key && members_hash.include?(symbolized_key) h[requested_key] = Primitive.object_hidden_var_get(self, symbolized_key) else return h From a07ec4da1a07e2439d3dea7013fd7c07eb1dcec1 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Fri, 7 Mar 2025 15:19:00 +0200 Subject: [PATCH 5/5] Refactor Struct#deconstruct_keys and Data#deconstruct_keys to rely on Array#[] to validate an index argument --- src/main/ruby/truffleruby/core/data.rb | 3 +-- src/main/ruby/truffleruby/core/struct.rb | 11 +---------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/main/ruby/truffleruby/core/data.rb b/src/main/ruby/truffleruby/core/data.rb index 7dd206c022ed..ccf7fe0c7e0a 100644 --- a/src/main/ruby/truffleruby/core/data.rb +++ b/src/main/ruby/truffleruby/core/data.rb @@ -174,8 +174,7 @@ def deconstruct_keys(keys) when String symbolized_key = requested_key.to_sym else - index = Truffle::Type.rb_convert_type(requested_key, Integer, :to_int) - symbolized_key = members[index] + symbolized_key = members[requested_key] end if symbolized_key && members_hash.include?(symbolized_key) diff --git a/src/main/ruby/truffleruby/core/struct.rb b/src/main/ruby/truffleruby/core/struct.rb index a5e4a4a45b83..815738b7f7af 100644 --- a/src/main/ruby/truffleruby/core/struct.rb +++ b/src/main/ruby/truffleruby/core/struct.rb @@ -263,15 +263,6 @@ def []=(var, obj) _attrs[var] end - private def check_index_var(var) - var = Truffle::Type.rb_convert_type(var, Integer, :to_int) - a_len = _attrs.length - - if var < a_len && var >= -a_len - _attrs[var] - end - end - def dig(key, *more) result = read_or_nil(key) if Primitive.nil?(result) || more.empty? @@ -353,7 +344,7 @@ def deconstruct_keys(keys) when String symbolized_key = requested_key.to_sym else - symbolized_key = check_index_var(requested_key) + symbolized_key = _attrs[requested_key] end if symbolized_key && _attrs.include?(symbolized_key)