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

ruby: repeated_field aliases each_index to each_with_index - thus incorrectly returning the each not the index #7806

Closed
jufemaiz opened this issue Aug 14, 2020 · 0 comments · Fixed by #15190
Assignees

Comments

@jufemaiz
Copy link
Contributor

jufemaiz commented Aug 14, 2020

Aliased method for each_index is invalid:

# array aliases into enumerable
alias_method :each_index, :each_with_index
alias_method :slice, :[]
alias_method :values_at, :select
alias_method :map, :collect

Ref:

What version of protobuf and what language are you using?
Version: master
Language: ruby

What operating system (Linux, Windows, ...) and version?

Docker: ruby:2.7-slim-buster

What runtime / compiler are you using (e.g., python version or gcc version)

N/A

What did you do?
Steps to reproduce the behavior:

  1. have a proto with a repeated_field
  2. build a ruby library
  3. make use of each_index

What did you expect to see

The index of the repeated field.

What did you see instead?

The repeated field's value instead.

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

Anything else we should know about your project / environment

N/A

@TeBoring TeBoring added the ruby label Aug 20, 2020
copybara-service bot pushed a commit that referenced this issue Dec 26, 2023
…11767)

Currently we're aliasing `each_index` to `each_with_index`, incorrectly passing both the index and the value of a repeated field to the block.

What we want is to just pass the index. Luckily this is a method on Ruby arrays, so we just wrap the native Ruby array method.

Fixes #7806

Closes #11767

COPYBARA_INTEGRATE_REVIEW=#11767 from shaldengeki:shaldengeki-repeated-field-each-index-returns-actual-index 874916c
FUTURE_COPYBARA_INTEGRATE_REVIEW=#11767 from shaldengeki:shaldengeki-repeated-field-each-index-returns-actual-index 874916c
PiperOrigin-RevId: 593820135
copybara-service bot pushed a commit that referenced this issue Dec 26, 2023
…11767)

Currently we're aliasing `each_index` to `each_with_index`, incorrectly passing both the index and the value of a repeated field to the block.

What we want is to just pass the index. Luckily this is a method on Ruby arrays, so we just wrap the native Ruby array method.

Fixes #7806

Closes #11767

COPYBARA_INTEGRATE_REVIEW=#11767 from shaldengeki:shaldengeki-repeated-field-each-index-returns-actual-index 874916c
FUTURE_COPYBARA_INTEGRATE_REVIEW=#11767 from shaldengeki:shaldengeki-repeated-field-each-index-returns-actual-index 874916c
PiperOrigin-RevId: 593820135
copybara-service bot pushed a commit that referenced this issue Dec 26, 2023
…11767)

Currently we're aliasing `each_index` to `each_with_index`, incorrectly passing both the index and the value of a repeated field to the block.

What we want is to just pass the index. Luckily this is a method on Ruby arrays, so we just wrap the native Ruby array method.

Fixes #7806

Closes #11767

COPYBARA_INTEGRATE_REVIEW=#11767 from shaldengeki:shaldengeki-repeated-field-each-index-returns-actual-index 874916c
PiperOrigin-RevId: 593835025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment