@@ -2387,7 +2387,7 @@ public RubyNode visitInterpolatedMatchLastLineNode(Nodes.InterpolatedMatchLastLi
2387
2387
public RubyNode visitInterpolatedRegularExpressionNode (Nodes .InterpolatedRegularExpressionNode node ) {
2388
2388
var encodingAndOptions = getRegexpEncodingAndOptions (new Nodes .RegularExpressionFlags (node .flags ));
2389
2389
var options = encodingAndOptions .options ;
2390
- final ToSNode [] children = translateInterpolatedParts (node .parts );
2390
+ final ToSNode [] children = translateInterpolatedPartsIgnoreForceEncodingFlags (node .parts );
2391
2391
2392
2392
final RubyEncoding encoding ;
2393
2393
if (!options .isKcodeDefault ()) { // explicit encoding
@@ -2526,6 +2526,31 @@ private ToSNode[] translateInterpolatedParts(Nodes.Node[] parts) {
2526
2526
return children ;
2527
2527
}
2528
2528
2529
+ /** Regexp encoding negotiation does not work correctly if such flags are kept, e.g. for /#{ }\xc2\xa1/e in
2530
+ * test_m17n.rb. Not clear what is a good solution yet. */
2531
+ private ToSNode [] translateInterpolatedPartsIgnoreForceEncodingFlags (Nodes .Node [] parts ) {
2532
+ final ToSNode [] children = new ToSNode [parts .length ];
2533
+
2534
+ for (int i = 0 ; i < parts .length ; i ++) {
2535
+ RubyNode expression ;
2536
+ if (parts [i ] instanceof Nodes .StringNode stringNode ) {
2537
+ short flags = stringNode .isFrozen () ? Nodes .StringFlags .FROZEN : NO_FLAGS ;
2538
+ Nodes .StringNode stringNodeNoForceEncoding = new Nodes .StringNode (flags , stringNode .unescaped ,
2539
+ stringNode .startOffset , stringNode .length );
2540
+
2541
+ // Prism might assign new line flag not to the outer regexp node but to its first part instead
2542
+ copyNewLineFlag (stringNode , stringNodeNoForceEncoding );
2543
+
2544
+ expression = stringNodeNoForceEncoding .accept (this );
2545
+ } else {
2546
+ expression = parts [i ].accept (this );
2547
+ }
2548
+ children [i ] = ToSNodeGen .create (expression );
2549
+ }
2550
+
2551
+ return children ;
2552
+ }
2553
+
2529
2554
@ Override
2530
2555
public RubyNode visitItParametersNode (Nodes .ItParametersNode node ) {
2531
2556
throw CompilerDirectives .shouldNotReachHere ("ItParametersNode is only from Ruby 3.4" );
0 commit comments