@@ -317,16 +317,20 @@ public Object slice(RubyString string, int start, int length) {
317
317
@ CoreMethod (names = "[]=" , required = 2 , lowerFixnumParameters = 0 )
318
318
public abstract static class ElementSetNode extends CoreMethodNode {
319
319
320
+ @ Child private ToStrNode toStrNode ;
321
+
320
322
public ElementSetNode (RubyContext context , SourceSection sourceSection ) {
321
323
super (context , sourceSection );
324
+ toStrNode = ToStrNodeFactory .create (context , sourceSection , null );
322
325
}
323
326
324
327
public ElementSetNode (ElementSetNode prev ) {
325
328
super (prev );
329
+ toStrNode = prev .toStrNode ;
326
330
}
327
331
328
332
@ Specialization
329
- public RubyString elementSet (RubyString string , int index , RubyString replacement ) {
333
+ public RubyString elementSet (VirtualFrame frame , RubyString string , int index , Object replacement ) {
330
334
notDesignedForCompilation ();
331
335
332
336
if (string .isFrozen ()) {
@@ -350,13 +354,14 @@ public RubyString elementSet(RubyString string, int index, RubyString replacemen
350
354
throw new RaiseException (getContext ().getCoreLibrary ().indexError (String .format ("index %d out of string" , index ), this ));
351
355
}
352
356
353
- StringSupport .replaceInternal19 (index , 1 , string , replacement );
357
+ final RubyString coerced = toStrNode .executeRubyString (frame , replacement );
358
+ StringSupport .replaceInternal19 (index , 1 , string , coerced );
354
359
355
- return replacement ;
360
+ return coerced ;
356
361
}
357
362
358
363
@ Specialization
359
- public RubyString elementSet (RubyString string , RubyRange .IntegerFixnumRange range , RubyString replacement ) {
364
+ public RubyString elementSet (VirtualFrame frame , RubyString string , RubyRange .IntegerFixnumRange range , Object replacement ) {
360
365
notDesignedForCompilation ();
361
366
362
367
if (string .isFrozen ()) {
@@ -400,9 +405,10 @@ public RubyString elementSet(RubyString string, RubyRange.IntegerFixnumRange ran
400
405
length = 0 ;
401
406
}
402
407
403
- StringSupport .replaceInternal19 (begin , length , string , replacement );
408
+ final RubyString coerced = toStrNode .executeRubyString (frame , replacement );
409
+ StringSupport .replaceInternal19 (begin , length , string , coerced );
404
410
405
- return replacement ;
411
+ return coerced ;
406
412
}
407
413
}
408
414
0 commit comments