Skip to content

Commit 98997de

Browse files
committed
Fix a few RubyString#toString() calls
(cherry picked from commit 4cb098a)
1 parent 9a74df8 commit 98997de

File tree

7 files changed

+22
-15
lines changed

7 files changed

+22
-15
lines changed

src/main/java/org/truffleruby/core/array/ArrayNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,7 @@ private RubyString finishPack(int formatLength, BytesResult result) {
15911591

15921592
@TruffleBoundary
15931593
protected RootCallTarget compileFormat(RubyString format) {
1594-
return new PackCompiler(getContext(), this).compile(format.toString());
1594+
return new PackCompiler(getContext(), this).compile(format.getJavaString());
15951595
}
15961596

15971597
protected int getCacheLimit() {

src/main/java/org/truffleruby/core/exception/CoreExceptions.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ public void showExceptionIfDebug(RubyClass rubyClass, Object message, Backtrace
8989
}
9090
}
9191

92+
public String inspectReceiver(Object receiver) {
93+
RubyString rubyString = (RubyString) context.send(
94+
context.getCoreLibrary().truffleExceptionOperationsModule,
95+
"receiver_string",
96+
receiver);
97+
return rubyString.getJavaString();
98+
}
99+
92100
// ArgumentError
93101

94102
public RubyException argumentErrorOneHashRequired(Node currentNode) {
@@ -488,17 +496,17 @@ public RubyException typeErrorCantConvertInto(Object from, String toClass, Node
488496

489497
@TruffleBoundary
490498
public RubyException typeErrorIsNotA(Object value, String expectedType, Node currentNode) {
491-
return typeErrorIsNotA(value.toString(), expectedType, currentNode);
499+
return typeErrorIsNotA(inspectReceiver(value), expectedType, currentNode);
492500
}
493501

494502
@TruffleBoundary
495503
public RubyException typeErrorIsNotA(String value, String expectedType, Node currentNode) {
496-
return typeError(StringUtils.format("%s is not a %s", value, expectedType), currentNode);
504+
return typeError(value + " is not a " + expectedType, currentNode);
497505
}
498506

499507
@TruffleBoundary
500508
public RubyException typeErrorIsNotAClassModule(Object value, Node currentNode) {
501-
return typeError(StringUtils.format("%s is not a class/module", value), currentNode);
509+
return typeError(inspectReceiver(value) + " is not a class/module", currentNode);
502510
}
503511

504512
@TruffleBoundary

src/main/java/org/truffleruby/core/regexp/MatchDataNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,11 @@ private int getBackRefFromRope(RubyMatchData matchData, Object index, Rope value
389389
0,
390390
value.byteLength(),
391391
matchData.region);
392-
} catch (final ValueException e) {
392+
} catch (ValueException e) {
393393
throw new RaiseException(
394394
getContext(),
395395
coreExceptions().indexError(
396-
StringUtils.format("undefined group name reference: %s", index.toString()),
396+
StringUtils.format("undefined group name reference: %s", index),
397397
this));
398398
}
399399
}

src/main/java/org/truffleruby/core/rope/Rope.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public abstract class Rope implements Comparable<Rope> {
2121
public static final int NUMBER_OF_CONCRETE_CLASSES = 8;
2222

2323
// Useful for debugging. Setting to false allow to catch wrong usages.
24-
protected static final boolean ALLOW_TO_STRING = true;
24+
protected static final boolean ALLOW_TO_STRING = false;
2525

2626
public final Encoding encoding;
2727
private final int byteLength;

src/main/java/org/truffleruby/parser/parser/RubyParser.java

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/org/truffleruby/parser/parser/RubyParser.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ rel_expr : arg relop arg %prec tGT {
12591259
$$ = support.getOperatorCallNode($1, $2, $3, lexer.getPosition());
12601260
}
12611261
| rel_expr relop arg %prec tGT {
1262-
support.warning(lexer.getPosition(), "comparison '" + $2 + "' after comparison");
1262+
support.warning(lexer.getPosition(), "comparison '" + $2.getString() + "' after comparison");
12631263
$$ = support.getOperatorCallNode($1, $2, $3, lexer.getPosition());
12641264
}
12651265

src/main/ruby/truffleruby/core/truffle/exception_operations.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def self.class_name(receiver)
4848
end
4949

5050
# MRI: name_err_mesg_to_str
51-
def self.receiver_string(exception)
52-
receiver = exception.receiver
51+
def self.receiver_string(receiver)
5352
ret = begin
5453
if Primitive.object_respond_to?(receiver, :inspect, false)
5554
Truffle::Type.rb_inspect(receiver)
@@ -157,19 +156,19 @@ def self.comparison_error_message(x, y)
157156
end
158157

159158
NO_METHOD_ERROR = Proc.new do |exception|
160-
format("undefined method `%s' for %s", exception.name, receiver_string(exception))
159+
format("undefined method `%s' for %s", exception.name, receiver_string(exception.receiver))
161160
end
162161

163162
NO_LOCAL_VARIABLE_OR_METHOD_ERROR = Proc.new do |exception|
164-
format("undefined local variable or method `%s' for %s", exception.name, receiver_string(exception))
163+
format("undefined local variable or method `%s' for %s", exception.name, receiver_string(exception.receiver))
165164
end
166165

167166
PRIVATE_METHOD_ERROR = Proc.new do |exception|
168-
format("private method `%s' called for %s", exception.name, receiver_string(exception))
167+
format("private method `%s' called for %s", exception.name, receiver_string(exception.receiver))
169168
end
170169

171170
PROTECTED_METHOD_ERROR = Proc.new do |exception|
172-
format("protected method `%s' called for %s", exception.name, receiver_string(exception))
171+
format("protected method `%s' called for %s", exception.name, receiver_string(exception.receiver))
173172
end
174173

175174
SUPER_METHOD_ERROR = Proc.new do |exception|

0 commit comments

Comments
 (0)