This fixes https://bugs.ruby-lang.org/issues/18038. The provided
reproduction showed that this happens in heredocs with double
interpolation. In this case `DSTR` was getting returned but needs to be
convered to a `EVSTR` which is what is returned by the function. There
may be an additional bug here that we weren't able to produce. It seems
odd that `STR` returns `DSTR` while everything else should return
`EVSTR` since the function is `new_evstr`.

[Bug #18038][ruby-core:104597]

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
This commit is contained in:
eileencodes 2021-07-20 13:53:22 -04:00 коммит произвёл Aaron Patterson
Родитель fa308a683d
Коммит b940a45357
2 изменённых файлов: 30 добавлений и 1 удалений

Просмотреть файл

@ -10181,7 +10181,10 @@ new_evstr(struct parser_params *p, NODE *node, const YYLTYPE *loc)
switch (nd_type(node)) {
case NODE_STR:
nd_set_type(node, NODE_DSTR);
case NODE_DSTR: case NODE_EVSTR:
return node;
case NODE_DSTR:
break;
case NODE_EVSTR:
return node;
}
}

Просмотреть файл

@ -1080,6 +1080,32 @@ x = __ENCODING__
end;
end
def test_heredoc_interpolation
var = 1
v1 = <<~HEREDOC
something
#{"/#{var}"}
HEREDOC
v2 = <<~HEREDOC
something
#{other = "/#{var}"}
HEREDOC
v3 = <<~HEREDOC
something
#{("/#{var}")}
HEREDOC
assert_equal "something\n/1\n", v1
assert_equal "something\n/1\n", v2
assert_equal "something\n/1\n", v3
assert_equal v1, v2
assert_equal v2, v3
assert_equal v1, v3
end
def test_unexpected_token_error
assert_syntax_error('"x"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', /unexpected/)
end