Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array#rassoc should try to convert to array implicitly. Fixes #20003 #8904

Merged
merged 3 commits into from
Nov 29, 2023

Conversation

bolshakov
Copy link
Contributor

@bolshakov bolshakov commented Nov 12, 2023

Fixes https://bugs.ruby-lang.org/issues/20003

There is a difference between behaviour of Array#assoc and Array#rassoc. The first one performs implicit conversion (calls #to_ary) while the former does not.

class ArrayConvertible
  def initialize(*values)
    @values = values;
  end

  def to_ary
    @values
  end
end

s1 = [1, 2]
s2 = ArrayConvertible.new(2, 3)
a = [s1, s2]

The a.assoc(2) call returns [2, 3] as expected. However, a.rassoc(3) returns nil

Expected behaviour: a.rassoc(3) returns [2, 3] in such cases.

@bolshakov bolshakov force-pushed the fix-rassoc-implicit-conversion branch from 84c7835 to b0e0d3b Compare November 12, 2023 20:24
@bolshakov bolshakov marked this pull request as ready for review November 12, 2023 20:32
@mame mame force-pushed the fix-rassoc-implicit-conversion branch from b0e0d3b to 38e8902 Compare November 28, 2023 07:20
@mame mame enabled auto-merge (rebase) November 28, 2023 07:20
@mame mame disabled auto-merge November 28, 2023 07:21
@mame mame enabled auto-merge (squash) November 28, 2023 07:22
auto-merge was automatically disabled November 28, 2023 09:01

Head branch was pushed to by a user without write access

@bolshakov bolshakov force-pushed the fix-rassoc-implicit-conversion branch from 38e8902 to b0e0d3b Compare November 28, 2023 09:01
@bolshakov
Copy link
Contributor Author

@mame now everything passed, except the spec I introduced here ruby/spec#1110 I will update it after the merge

@mame
Copy link
Member

mame commented Nov 28, 2023

@bolshakov Could you update the mirrored spec file in this ruby/ruby repo directly? Changing ruby/spec is not reflected in real time. I want to keep the CI green.

@bolshakov bolshakov force-pushed the fix-rassoc-implicit-conversion branch from 73c0455 to 44ad339 Compare November 28, 2023 12:47
@bolshakov
Copy link
Contributor Author

@mame I updated the specs, and all checks are green now.

@mame mame merged commit bed014e into ruby:master Nov 29, 2023
98 checks passed
@bolshakov bolshakov deleted the fix-rassoc-implicit-conversion branch November 29, 2023 10:25
headius added a commit to jruby/jruby that referenced this pull request Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants