|
24 | 24 | import org.truffleruby.language.control.RaiseException;
|
25 | 25 | import org.truffleruby.language.dispatch.DispatchNode;
|
26 | 26 | import org.truffleruby.language.library.RubyStringLibrary;
|
27 |
| -import org.truffleruby.utils.Utils; |
28 | 27 |
|
29 | 28 | @GenerateUncached
|
30 | 29 | @NodeChild(value = "valueNode", type = RubyBaseNodeWithExecute.class)
|
@@ -85,22 +84,15 @@ protected RubySymbol rubyStringUncached(Object str,
|
85 | 84 | @Specialization(guards = { "!isRubySymbol(object)", "!isString(object)", "isNotRubyString(object)" })
|
86 | 85 | protected RubySymbol toStr(Object object,
|
87 | 86 | @Cached BranchProfile errorProfile,
|
88 |
| - @Cached DispatchNode toStr, |
| 87 | + @Cached DispatchNode toStrNode, |
89 | 88 | @Cached RubyStringLibrary libString,
|
90 | 89 | @Cached ToSymbolNode toSymbolNode) {
|
91 |
| - final Object coerced; |
92 |
| - try { |
93 |
| - coerced = toStr.call(object, "to_str"); |
94 |
| - } catch (RaiseException e) { |
95 |
| - errorProfile.enter(); |
96 |
| - if (e.getException().getLogicalClass() == coreLibrary().noMethodErrorClass) { |
97 |
| - throw new RaiseException(getContext(), coreExceptions().typeError( |
98 |
| - Utils.concat(object, " is not a symbol nor a string"), |
99 |
| - this)); |
100 |
| - } else { |
101 |
| - throw e; |
102 |
| - } |
103 |
| - } |
| 90 | + var coerced = toStrNode.call( |
| 91 | + coreLibrary().truffleTypeModule, |
| 92 | + "rb_convert_type", |
| 93 | + object, |
| 94 | + coreLibrary().stringClass, |
| 95 | + coreSymbols().TO_STR); |
104 | 96 |
|
105 | 97 | if (libString.isRubyString(coerced)) {
|
106 | 98 | return toSymbolNode.execute(coerced);
|
|
0 commit comments