27
27
import org .truffleruby .core .array .ArrayUtils ;
28
28
import org .truffleruby .core .cast .BooleanCastNode ;
29
29
import org .truffleruby .core .cast .NameToJavaStringNode ;
30
+ import org .truffleruby .core .cast .ToSymbolNode ;
30
31
import org .truffleruby .core .klass .RubyClass ;
31
32
import org .truffleruby .core .method .RubyMethod ;
33
+ import org .truffleruby .core .symbol .RubySymbol ;
32
34
import org .truffleruby .language .RubyBaseNode ;
33
35
import org .truffleruby .language .RubyContextSourceNode ;
34
36
import org .truffleruby .language .RubyNode ;
@@ -62,6 +64,7 @@ protected RubyMethod getMethodObject(
62
64
@ CachedContext (RubyLanguage .class ) RubyContext context ,
63
65
@ Cached NameToJavaStringNode nameToJavaStringNode ,
64
66
@ Cached LookupMethodOnSelfNode lookupMethodNode ,
67
+ @ Cached ToSymbolNode toSymbolNode ,
65
68
@ Cached DispatchNode respondToMissingNode ,
66
69
@ Cached BooleanCastNode booleanCastNode ,
67
70
@ Cached ConditionProfile notFoundProfile ,
@@ -80,18 +83,20 @@ protected RubyMethod getMethodObject(
80
83
}
81
84
82
85
final String normalizedName = nameToJavaStringNode .execute (name );
83
- InternalMethod method = lookupMethodNode
84
- .execute (frame , self , normalizedName , dispatchConfig );
86
+ InternalMethod method = lookupMethodNode .execute (frame , self , normalizedName , dispatchConfig );
85
87
86
88
if (notFoundProfile .profile (method == null )) {
89
+ final RubySymbol symbolName = toSymbolNode .execute (name );
87
90
final Object respondToMissing = respondToMissingNode
88
- .call (self , "respond_to_missing?" , name , dispatchConfig .ignoreVisibility );
91
+ .call (self , "respond_to_missing?" , symbolName , dispatchConfig .ignoreVisibility );
89
92
if (respondToMissingProfile .profile (booleanCastNode .executeToBoolean (respondToMissing ))) {
90
- /** refinements should not affect BasicObject#method_missing */
91
- RubyArguments .setDeclarationContext (frame , originalDeclarationContext );
93
+ if (frame != null ) {
94
+ // refinements should not affect BasicObject#method_missing
95
+ RubyArguments .setDeclarationContext (frame , originalDeclarationContext );
96
+ }
92
97
final InternalMethod methodMissing = lookupMethodNode
93
98
.execute (frame , self , "method_missing" , dispatchConfig );
94
- method = createMissingMethod (self , name , normalizedName , methodMissing , language , context );
99
+ method = createMissingMethod (self , symbolName , normalizedName , methodMissing , language , context );
95
100
} else {
96
101
throw new RaiseException (
97
102
context ,
@@ -111,7 +116,7 @@ protected RubyMethod getMethodObject(
111
116
}
112
117
113
118
@ TruffleBoundary
114
- private InternalMethod createMissingMethod (Object self , Object name , String normalizedName ,
119
+ private InternalMethod createMissingMethod (Object self , RubySymbol name , String normalizedName ,
115
120
InternalMethod methodMissing , RubyLanguage language , RubyContext context ) {
116
121
final SharedMethodInfo info = methodMissing
117
122
.getSharedMethodInfo ()
@@ -140,10 +145,11 @@ private InternalMethod createMissingMethod(Object self, Object name, String norm
140
145
}
141
146
142
147
private static class CallMethodMissingWithStaticName extends RubyContextSourceNode {
143
- private final Object methodName ;
148
+
149
+ private final RubySymbol methodName ;
144
150
@ Child private DispatchNode methodMissing = DispatchNode .create ();
145
151
146
- public CallMethodMissingWithStaticName (Object methodName ) {
152
+ public CallMethodMissingWithStaticName (RubySymbol methodName ) {
147
153
this .methodName = methodName ;
148
154
}
149
155
0 commit comments