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

Regression: multiple refinements of the same class #5550

Closed
palkan opened this Issue Jan 6, 2019 · 3 comments

Comments

Projects
None yet
3 participants
@palkan
Copy link

palkan commented Jan 6, 2019

Environment

  • JRuby version: jruby 9.2.5.0 (2.5.0) 2018-12-06 6d5a228 OpenJDK 64-Bit Server VM 25.181-b13 on 1.8.0_181-8u181-b13-2~deb9u1-b13 +jit [linux-x86_64]

Expected Behavior

Given the code below:

class A
  def foo
    puts "foo"
    self
  end
end

using(Module.new do
  refine A do
    def baz
      puts "bar"
      self
    end
  end
end)

using(Module.new do
  refine A do
    def bar
      puts "bar"
      self
    end
  end
end)

begin
  A.new.foo.baz.bar
rescue => e
  p e.message
end

begin
  A.new.foo.bar.baz
rescue => e
  p e.message
end

I expect it to print:

"foo"
"baz"
"bar"
"foo"
"bar"
"baz"

The code below worked in 9.1.7.0 (just checked: broken since 9.2.0.0).

Actual Behavior

It prints exceptions:

"foo"
"undefined method `baz' for #<A:0x1c3a4799>"
"foo"
"bar"
"undefined method `baz' for #<A:0x3043fe0e>"

If I change the order of using, the bar method becomes undefined; hence only the last added refinement for the class is activated.

@enebo enebo added this to the JRuby 9.2.6.0 milestone Jan 9, 2019

@enebo enebo modified the milestones: JRuby 9.2.6.0, JRuby 9.2.7.0 Feb 11, 2019

@headius

This comment has been minimized.

Copy link
Member

headius commented Feb 26, 2019

Fixed once #5627 lands.

Note that MRI 2.5 does not match your expected output, but does match JRuby output after #5627:

[] ~/projects/jruby $ jruby blah.rb
foo
bar
bar
foo
bar
bar

[] ~/projects/jruby $ rvm ruby-2.5.3 do ruby blah.rb
foo
bar
bar
foo
bar
bar

If you have some other expectation we should dig into that...but otherwise we're going to call this fixed since it matches MRI.

@palkan

This comment has been minimized.

Copy link
Author

palkan commented Feb 26, 2019

Note that MRI 2.5 does not match your expected output, but does match JRuby output after
If you have some other expectation we should dig into that

Sorry, there is a typo in the example script from the PR description.
So, it should be fixed.

Thanks!

@headius

This comment has been minimized.

Copy link
Member

headius commented Apr 8, 2019

Fixed for 9.2.7 (note this output differs from description due to a typo by @palkan):

[] ~/projects/jruby $ cat blah.rb
class A
  def foo
    puts "foo"
    self
  end
end

using(Module.new do
  refine A do
    def baz
      puts "bar"
      self
    end
  end
end)

using(Module.new do
  refine A do
    def bar
      puts "bar"
      self
    end
  end
end)

begin
  A.new.foo.baz.bar
rescue => e
  p e.message
end

begin
  A.new.foo.bar.baz
rescue => e
  p e.message
end
[] ~/projects/jruby $ rvm ruby-2.5.3 do ruby blah.rb
foo
bar
bar
foo
bar
bar

[] ~/projects/jruby $ jruby -v blah.rb
jruby 9.2.7.0-SNAPSHOT (2.5.3) 2019-04-08 2122e9f OpenJDK 64-Bit Server VM 25.202-b08 on 1.8.0_202-b08 +jit [darwin-x86_64]
foo
bar
bar
foo
bar
bar

@headius headius closed this Apr 8, 2019

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.