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] Undefining a method causes respond_to? to break #2915

Closed
nirvdrum opened this issue May 7, 2015 · 1 comment
Closed

[Truffle] Undefining a method causes respond_to? to break #2915

nirvdrum opened this issue May 7, 2015 · 1 comment
Assignees

Comments

@nirvdrum
Copy link
Contributor

nirvdrum commented May 7, 2015

When we undefine a method it causes Truffle's respond_to? logic to fail. respond_to? is implemented to return false if a method lookup fails, but if the lookup succeeds but is marked as undefined, Truffle raises an exception instead.

A small reproduction case:

class Wrapper
  def x
  end

  def y
    p respond_to?(:x)

    singleton_class.send(:undef_method, :x)

    p respond_to?(:x)
  end
end

Wrapper.new.y

And running in MRI:

> ruby -v undefined.rb 
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
true
false

Running in JRuby+Truffle:

> bin/jruby -X+T -v undefined.rb 
jruby 9.0.0.0-SNAPSHOT (2.2.2) 2015-05-04 af42d09 Java HotSpot(TM) 64-Bit Server VM 25.45-b02 on 1.8.0_45-b14 +jit [linux-amd64]
true
undefined.rb:10:in `respond_to?': undefined method `x' for Wrapper (NoMethodError)
    from undefined.rb:10:in `y'
    from undefined.rb:14:in `<main>'

The raise originates in:

if (method.isUndefined()) {
throw new RaiseException(getContext().getCoreLibrary().noMethodErrorOnReceiver(name, receiver, this));
}

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

Fixed in 55b57d5

@chrisseaton chrisseaton added this to the truffle-dev milestone May 8, 2015
@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