ruby / ruby/spec

Need specs for each_with_index + Enumerable method interaction

Open
#1,283 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
622
Forks
402
Avg merge
14h 51m
Merged PRs (30d)
6

Description

There are at least three cases from jruby/jruby#8345 where an interaction between an each_with_index Enumerator and an Enumerable method was or is broken in JRuby:

  • to_h
  • uniq
  • zip

Of these, we've fixed uniq and I have a fix in process for to_h but I'm not sure where to put specs for this kind of interaction.

My first thought was in Enumerable specs, since that's where I had to fix things, but I have not come up with a reproduction that doesn't use an each_with_index enumerator. All cases should be specified, though only a few exhibited this differing behavior between CRuby and JRuby.

Running the same example script against TruffleRuby shows similar issues, so I think getting these cases spec'ed would benefit all impls:

$ diff truffleruby_enum_args.txt ruby_enum_args.txt                  
1c1
< truffleruby 24.2.1, like ruby 3.3.7, Oracle GraalVM Native [arm64-darwin20]
---
> ruby 3.3.3 (2024-06-12 revision f1c7b6f435) [arm64-darwin23]
25c25
< filter_map [[1, 2], 0]
---
> filter_map [1, 2]
65c65
< to_h [[1, 2], 0]
---
> to_h [1, 2]
67c67
< uniq [[1, 2], 0]
---
> uniq [1, 2]
70c70
< zip [[[1, 2], 0]]
---
> zip [[1, 2], 0]

It's also possible CRuby is wrong to have special behavior for these methods.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the existing Enumerable specs and the issue's example outputs for each_with_index interactions with to_h, uniq, and zip. Reproduce the cases across implementations, then determine where these interactions belong and what behavior the specs should require. Done means all three cases are covered and the expected behavior is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.