@@ -317,16 +317,20 @@ public Object slice(RubyString string, int start, int length) {
317317 @ CoreMethod (names = "[]=" , required = 2 , lowerFixnumParameters = 0 )
318318 public abstract static class ElementSetNode extends CoreMethodNode {
319319
320+ @ Child private ToStrNode toStrNode ;
321+
320322 public ElementSetNode (RubyContext context , SourceSection sourceSection ) {
321323 super (context , sourceSection );
324+ toStrNode = ToStrNodeFactory .create (context , sourceSection , null );
322325 }
323326
324327 public ElementSetNode (ElementSetNode prev ) {
325328 super (prev );
329+ toStrNode = prev .toStrNode ;
326330 }
327331
328332 @ Specialization
329- public RubyString elementSet (RubyString string , int index , RubyString replacement ) {
333+ public RubyString elementSet (VirtualFrame frame , RubyString string , int index , Object replacement ) {
330334 notDesignedForCompilation ();
331335
332336 if (string .isFrozen ()) {
@@ -350,13 +354,14 @@ public RubyString elementSet(RubyString string, int index, RubyString replacemen
350354 throw new RaiseException (getContext ().getCoreLibrary ().indexError (String .format ("index %d out of string" , index ), this ));
351355 }
352356
353- StringSupport .replaceInternal19 (index , 1 , string , replacement );
357+ final RubyString coerced = toStrNode .executeRubyString (frame , replacement );
358+ StringSupport .replaceInternal19 (index , 1 , string , coerced );
354359
355- return replacement ;
360+ return coerced ;
356361 }
357362
358363 @ 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 ) {
360365 notDesignedForCompilation ();
361366
362367 if (string .isFrozen ()) {
@@ -400,9 +405,10 @@ public RubyString elementSet(RubyString string, RubyRange.IntegerFixnumRange ran
400405 length = 0 ;
401406 }
402407
403- StringSupport .replaceInternal19 (begin , length , string , replacement );
408+ final RubyString coerced = toStrNode .executeRubyString (frame , replacement );
409+ StringSupport .replaceInternal19 (begin , length , string , coerced );
404410
405- return replacement ;
411+ return coerced ;
406412 }
407413 }
408414
0 commit comments