oracle / truffleruby

A high performance implementation of the Ruby programming language, built on GraalVM.
https://www.graalvm.org/ruby/
Other
3.02k stars 185 forks source link

Struct#values_at should raise IndexError if out of bounds #2773

Closed djberg96 closed 1 year ago

djberg96 commented 1 year ago

truffleruby 22.3.0, like ruby 3.0.3, GraalVM CE Native [x86_64-darwin]

As per the title, MRI raises an IndexError if the value provided to the values_at method is out of bounds. Currently TruffleRuby returns [nil].

Struct.new('ValuesAt', :a, :b, :c, :d, :e, :f)
struct = Struct::ValuesAt.new(1, 2, 3, 4, 5)
p struct.values_at(99) # => Should raise "offset 99 too large for struct(size:6) (IndexError)"
eregon commented 1 year ago

Thanks for the report, this should be fairly easy to fix in https://github.com/oracle/truffleruby/blob/master/src/main/ruby/truffleruby/core/struct.rb

andrykonchin commented 1 year ago

Fixed in 7adb9cb54d00867272aa1e50a5ec32507695cd52