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

Refinements in eval with binding #6017

Closed
palkan opened this issue Jan 4, 2020 · 4 comments
Closed

Refinements in eval with binding #6017

palkan opened this issue Jan 4, 2020 · 4 comments

Comments

@palkan
Copy link

palkan commented Jan 4, 2020

Environment

  • JRuby version: jruby 9.2.8.0 (2.5.3) 2019-08-12 a1ac7ff OpenJDK 64-Bit Server VM 25.232-b09 on 1.8.0_232-b09 +jit [linux-x86_64]
  • Operating system and platform: Linux c2e6ee70592c 4.9.125-linuxkit break script engine #1 SMP Fri Sep 7 08:20:28 UTC 2018 x86_64 GNU/Linux

Expected Behavior

Expected this script to behave the same way as in MRI 2.6.5:

# test.rb
using(Module.new do
  refine String do
    def foo
      "bar"
    end
  end
end)

eval "\n#{<<~'END_of_GUARD'}", binding, __FILE__, __LINE__
  p "foo".foo
END_of_GUARD
$ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]

$ ruby test.rb
"bar"

Actual Behavior

$ ruby -v
jruby 9.2.8.0 (2.5.3) 2019-08-12 a1ac7ff OpenJDK 64-Bit Server VM 25.232-b09 on 1.8.0_232-b09 +jit [linux-x86_64]

$ ruby test.rb
NoMethodError: undefined method `foo' for "foo":String
Did you mean?  fork
  <main> at tmp/eval_refine.rb:10
    eval at org/jruby/RubyKernel.java:1061
  <main> at tmp/eval_refine.rb:9

Moving using into eval resolves the issue.

palkan added a commit to ruby-next/ruby-next that referenced this issue Jan 4, 2020
palkan added a commit to ruby-next/ruby-next that referenced this issue Jan 4, 2020
@headius
Copy link
Member

headius commented Jan 6, 2020

It would appear that the refinement scope is not being seen by the eval scope here.

@headius headius added this to the JRuby 9.2.10.0 milestone Jan 6, 2020
@headius
Copy link
Member

headius commented Feb 12, 2020

I have a fix locally. There does not appear to be any specs... perhaps you could contribute some to https://github.com/ruby/spec?

headius added a commit that referenced this issue Feb 12, 2020
@headius
Copy link
Member

headius commented Feb 12, 2020

FYI I did add one simple spec but it would be great to expand that for other forms of eval + binding.

@palkan
Copy link
Author

palkan commented Jul 24, 2020

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

2 participants