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() does not coerce according to MRI 1.9 logic #1962

Closed
headius opened this Issue Sep 10, 2014 · 4 comments

Comments

Projects
None yet
3 participants
@headius
Copy link
Member

commented Sep 10, 2014

The following code should work:

class Foo
  def method_missing(name, *args)
    []
  end
end

fail unless [] == Array(Foo.new)

The existing logic (possibly from 1.8) does not follow the method_missing path. If there's no to_ary or to_a, the object is just wrapped in an array.

This is the cause of the first bunch of errors in this Travis CI job (thanks @rkh): https://travis-ci.org/travis-ci/travis-yaml/builds/34826144

@headius headius self-assigned this Sep 10, 2014

@headius headius added this to the JRuby 1.7.16 milestone Sep 10, 2014

headius added a commit that referenced this issue Sep 10, 2014

headius added a commit that referenced this issue Sep 10, 2014

@headius

This comment has been minimized.

Copy link
Member Author

commented Sep 10, 2014

Fixed in 2b0c320. Specs in d4eb922.

@headius headius closed this Sep 10, 2014

@enebo enebo modified the milestones: JRuby 1.7.17, JRuby 1.7.16 Sep 25, 2014

@enebo

This comment has been minimized.

Copy link
Member

commented Sep 25, 2014

Reverted in jruby-1_7 only because this was causing issues with Rails 4. I also noticed we are not properly handling:

class Foo
  private
  def to_ary
    []
  end

  def to_a
    []
  end
end

p Array(Foo.new)

This example is probably not the Rails 4 issue but it is in the general pool of differences during coercion we are not properly observing.

@enebo enebo reopened this Sep 25, 2014

@enebo

This comment has been minimized.

Copy link
Member

commented Sep 25, 2014

1.7.16 is out and I re-cherry-pick'd the origina commit on jruby-1_7 branch. So we have a few weeks to figure out the Rails issue with this.

@bbrowning

This comment has been minimized.

Copy link
Contributor

commented Sep 26, 2014

This simplest reproducer for the Rails 4 issue I can come up with is this:

class Foo
  private
  def to_ary; end
  def to_a; end
  def method_missing(method, *args)
    super
  end
end
Array(Foo.new)

Running this results in:

NoMethodError: to_ary
   Array at org/jruby/RubyKernel.java:386

@headius headius closed this in aafb40b Sep 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.