Skip to content

Commit

Permalink
Fixes #3326. JRuby 9.0.1.0 vs. MRI 2.2.2 define_method inconsistency
Browse files Browse the repository at this point in the history
Problem was when we switched from arity to signature we added a new
call and we passed the block arg passed to the symbol proc rather
than the symbol proc itself.  Getting this to trigger did not really
fit into any standard ruby behavior so I made a regression spec for
it.  My guess is we only internally call the broken Java method if
the block is set in an uncommon way (although I am not entirely
sure what that is...but define_method will cause it to happen).
  • Loading branch information
enebo committed Nov 2, 2016
1 parent 07ad439 commit 643d442
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubySymbol.java
Expand Up @@ -1043,7 +1043,7 @@ private IRubyObject yieldInner(ThreadContext context, RubyArray array, Block blo

@Override
public IRubyObject yield(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self, Block blockArg) {
RubyProc.prepareArgs(context, block.type, blockArg.getBody(), args);
RubyProc.prepareArgs(context, block.type, this, args);
return yieldInner(context, RubyArray.newArrayMayCopy(context.runtime, args), blockArg);
}

Expand Down
15 changes: 15 additions & 0 deletions spec/regression/GH-3326_symbol_proc_should_be_callable.rb
@@ -0,0 +1,15 @@
require 'rspec'

describe "sym.to_proc in define_method" do
it "should not raise an ArgumentError" do
expect do
# Weirdly using the proc generated will end up changing
# something about the block which would in turn call a
# java version of yield in SymbolProcBody which was passing
# in its block param instead of itself for signature arity check.
s = :to_s.to_proc
define_method :gh3326, s
s[1]
end.not_to raise_error
end
end

0 comments on commit 643d442

Please sign in to comment.