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

Fix a bug where NameError#receiver raises an ArgumentError after #to_s is called #3832

Merged
merged 1 commit into from Apr 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions core/src/main/java/org/jruby/RubyNameError.java
Expand Up @@ -45,6 +45,7 @@
@JRubyClass(name="NameError", parent="StandardError")
public class RubyNameError extends RubyException {
private IRubyObject name;
private IRubyObject receiver;

/**
* Nested class whose instances act as thunks reacting to to_str method
Expand Down Expand Up @@ -207,6 +208,7 @@ static RubyException newNameError(IRubyObject recv, IRubyObject message, IRubyOb
@Override
public IRubyObject initialize(IRubyObject[] args, Block block) {
if ( args.length > 0 ) this.message = args[0];
if (message instanceof RubyNameErrorMessage) this.receiver = ((RubyNameErrorMessage) message).object;
if ( args.length > 1 ) this.name = args[1];
else this.name = getRuntime().getNil();
super.initialize(NULL_ARRAY, block); // message already set
Expand All @@ -231,8 +233,8 @@ public IRubyObject name() {

@JRubyMethod
public IRubyObject receiver(ThreadContext context) {
if (message instanceof RubyNameErrorMessage) {
return ((RubyNameErrorMessage) message).object;
if (receiver != null) {
return receiver;
}

throw context.runtime.newArgumentError("no receiver is available");
Expand Down