18
18
import com .oracle .truffle .api .frame .MaterializedFrame ;
19
19
import com .oracle .truffle .api .frame .VirtualFrame ;
20
20
import com .oracle .truffle .api .object .DynamicObject ;
21
+ import com .oracle .truffle .api .profiles .BranchProfile ;
21
22
import com .oracle .truffle .api .source .SourceSection ;
22
23
import org .truffleruby .Layouts ;
23
24
import org .truffleruby .builtins .CoreClass ;
27
28
import org .truffleruby .core .proc .ProcOperations ;
28
29
import org .truffleruby .core .proc .ProcType ;
29
30
import org .truffleruby .core .string .StringNodes ;
31
+ import org .truffleruby .language .RubyNode ;
30
32
import org .truffleruby .language .RubyRootNode ;
31
33
import org .truffleruby .language .SourceIndexLength ;
32
34
import org .truffleruby .language .Visibility ;
@@ -125,7 +127,7 @@ protected DynamicObject createProc(DeclarationContext declarationContext, Intern
125
127
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo (
126
128
sourceSection ,
127
129
method .getLexicalScope (),
128
- Arity .AT_LEAST_ONE ,
130
+ Arity .REST ,
129
131
null ,
130
132
Layouts .SYMBOL .getString (symbol ),
131
133
0 ,
@@ -138,7 +140,7 @@ protected DynamicObject createProc(DeclarationContext declarationContext, Intern
138
140
// binding as this simplifies the logic elsewhere in the runtime.
139
141
final MaterializedFrame declarationFrame = Truffle .getRuntime ().createMaterializedFrame (args , coreLibrary ().getEmptyDescriptor ());
140
142
final RubyRootNode rootNode = new RubyRootNode (getContext (), sourceSection , new FrameDescriptor (nil ()), sharedMethodInfo ,
141
- Translator .sequence (sourceIndexLength , Arrays .asList (Translator . createCheckArityNode ( Arity . AT_LEAST_ONE ), new SymbolProcNode (Layouts .SYMBOL .getString (symbol )))));
143
+ Translator .sequence (sourceIndexLength , Arrays .asList (new CheckReceiverArgumentNode ( ), new SymbolProcNode (Layouts .SYMBOL .getString (symbol )))));
142
144
143
145
final CallTarget callTarget = Truffle .getRuntime ().createCallTarget (rootNode );
144
146
@@ -168,6 +170,30 @@ protected DeclarationContext getDeclarationContext(VirtualFrame frame) {
168
170
protected FrameDescriptor getDescriptor (VirtualFrame frame ) {
169
171
return frame .getFrameDescriptor ();
170
172
}
173
+
174
+ /** Not using CheckArityNode as the message is different and arity is reported as -1. */
175
+ private static class CheckReceiverArgumentNode extends RubyNode {
176
+
177
+ private final BranchProfile noReceiverProfile = BranchProfile .create ();
178
+
179
+ @ Override
180
+ public void doExecuteVoid (VirtualFrame frame ) {
181
+ final int given = RubyArguments .getArgumentsCount (frame );
182
+
183
+ if (given == 0 ) {
184
+ noReceiverProfile .enter ();
185
+ throw new RaiseException (getContext (), coreExceptions ().argumentError ("no receiver given" , this ));
186
+ }
187
+ }
188
+
189
+ @ Override
190
+ public Object execute (VirtualFrame frame ) {
191
+ doExecuteVoid (frame );
192
+ return nil ();
193
+ }
194
+
195
+ }
196
+
171
197
}
172
198
173
199
@ CoreMethod (names = "to_s" )
0 commit comments