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

Refinements in method bodies aren't activated #3548

Closed
lazyatom opened this Issue Dec 18, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@lazyatom

lazyatom commented Dec 18, 2015

(Moved from a comment in #1062)

I've hit some strange behaviour trying to use refinements with version 9.0.4.0:

module Refinement
  refine Object do
    def new_method
      'new method!'
    end
  end
end

class Thing
  using Refinement

  p in_class_definition: Object.new.new_method

  def test
    p in_method: Object.new.new_method
  end
end

Thing.new.test

outputs

{:in_class_definition=>"new method!"}
NoMethodError: undefined method `new_method' for #<Object:0xcfa9dbf>
   test at test.rb:15
  <top> at test.rb:19

It seems like there's something amiss with the lexical scoping of the method; in MRI, methods defined with the lexical scope where a refinement is activated can make use of that refinement. Is this expected behaviour in JRuby as of 9.0.4.0?

@headius headius added this to the JRuby 9.1.0.0 milestone Dec 22, 2015

@headius headius closed this in 745654f Apr 22, 2016

headius added a commit that referenced this issue Apr 22, 2016

Search for refinements for target class and all superclasses.
If you refine Integer, then calls against Fixnum should see that
refinement.

Obviously this is super inefficient right now and caches nothing.

Relates to #3548.
@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius Apr 22, 2016

Member

tldr: when a refined call occurred in a method body, we would accidentally skip that method's containing class when looking for refinements.

Member

headius commented Apr 22, 2016

tldr: when a refined call occurred in a method body, we would accidentally skip that method's containing class when looking for refinements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment