From: "kiridaruma (Keiichiro Nishiyama) via ruby-core" Date: 2025-05-08T17:13:51+00:00 Subject: [ruby-core:121914] [Ruby Bug#20957] RangeError on Array#values_at with negative ranges Issue #20957 has been updated by kiridaruma (Keiichiro Nishiyama). I found almost same behavior at Array#fill ``` [0,1,2,3].fill(10, -10..-5) #=> RangeError [0,1,2,3].fill(10, -5..-3) #=> RangeError [0,1,2,3].fill(10, -3..3) #=> [0, 10, 10, 10] [0,1,2,3].fill(10, 3..10) #=> [0, 1, 2, 10, 10, 10, 10, 10, 10, 10, 10] ``` I noticed while reading Ruby's C code, and it seems that the reason is due to the mistaken calling of `rb_range_beg_len()`. ---------------------------------------- Bug #20957: RangeError on Array#values_at with negative ranges https://bugs.ruby-lang.org/issues/20957#change-112983 * Author: kyanagi (Kouhei Yanagita) * Status: Open * ruby -v: ruby 3.4.0dev (2024-12-13T10:19:31Z master 3cb79d4082) +PRISM [arm64-darwin22] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- ``` [0, 1, 2, 3].values_at(10) #=> [nil] [0, 1, 2, 3].values_at(10..10) #=> [nil] [0, 1, 2, 3].values_at(-10) #=> [nil] [0, 1, 2, 3].values_at(-10..-10) #=> 'Array#values_at': -10..-10 out of range (RangeError) ``` Is this the intended behavior? I am aware that this behavior was recently added to the documentation, but I would like to confirm whether it is the intended behavior. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/