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

[Truffle] Super passing wrong block #2914

Closed
nirvdrum opened this issue May 7, 2015 · 4 comments
Closed

[Truffle] Super passing wrong block #2914

nirvdrum opened this issue May 7, 2015 · 4 comments
Assignees

Comments

@nirvdrum
Copy link
Contributor

nirvdrum commented May 7, 2015

The tests for hike have a failure because we're not passing the correct block to super. I've extracted a smaller snippet to demonstrate the problem:

class UppercaseArray < Array
  def collect!
    super do |element|
      result = yield element
      normalize_element(result)
    end
  end

  def normalize_element(element)
    element.upcase
  end
end

a = UppercaseArray.new
a.push "a", "b", "c"
a.collect! { |x| x.downcase }

p a

This should print ["A", "B", "C"], but instead prints ["a", "b", "c"].

The block from the collect! call (i.e., the one with x.downcase) is being passed to super and the block attached to the super call is completely ignored.

@nirvdrum
Copy link
Contributor Author

nirvdrum commented May 7, 2015

If there's not a RubySpec covering the behavior, we should look at adding one.

@nirvdrum
Copy link
Contributor Author

nirvdrum commented May 7, 2015

I think this is a variation of the same problem (this time take from mime-types):

class HashWithArrayDefault < Hash
  def initialize
    super { |h, k| h[k] = [] }
  end
end

h = HashWithArrayDefault.new

p h[:not_exists] == []

This should print true, but instead prints false.

@chrisseaton chrisseaton self-assigned this May 8, 2015
@chrisseaton
Copy link
Contributor

Fixed in 36fbd3b

@chrisseaton chrisseaton added this to the truffle-dev milestone May 8, 2015
@chrisseaton
Copy link
Contributor

Spec in d15ad1d.

@enebo enebo added this to the Invalid or Duplicate milestone Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants