Issue #18038 has been updated by xtkoba (Tee KOBAYASHI).


It seems that `heredoc_dedent` in `parse.y` interacts badly with some sort of interpolation optimizations.

A patch is shown below to disable such optimizations.

```diff
--- a/parse.y
+++ b/parse.y
@@ -10184,7 +10184,9 @@ new_evstr(struct parser_params *p, NODE
 	switch (nd_type(node)) {
 	  case NODE_STR:
 	    nd_set_type(node, NODE_DSTR);
-	  case NODE_DSTR: case NODE_EVSTR:
+	  case NODE_DSTR:
+	    break;
+	  case NODE_EVSTR:
 	    return node;
 	}
     }
```


----------------------------------------
Bug #18038: Invalid interpolation in heredocs
https://bugs.ruby-lang.org/issues/18038#change-92928

* Author: maciej.mensfeld (Maciej Mensfeld)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
Given code as followed:

``` ruby
var = 1

v1 = <<~CMD
  something
  #{"/#{var}"}
CMD

v2 = <<~CMD
  something
  #{other = "/#{var}"}
CMD

v3 = <<~CMD
  something
  #{("/#{var}")}
CMD

p v1
p v2
p v3

p v1 == v2
p v2 == v3
```

result of running this:

```ruby
"something\n/\n"
"something\n/1\n"
"something\n/\n"
false
false
```

I would expect all heredocs to return the same value for all the cases. It seems the `other` variable assignment should be irrelevant but only with it the value "1" is present.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>