Issue #21758 has been updated by Earlopain (Earlopain _). It can be even simpler: ```rb %Q #{<<B} B ``` Lex output similarly contains B twice. ---------------------------------------- Bug #21758: Prism fails to parse heredoc within %Q literal split by another heredoc https://bugs.ruby-lang.org/issues/21758#change-115435 * Author: tompng (tomoya ishida) * Status: Open * ruby -v: ruby 4.0.0dev (2025-12-02T16:20:43Z master c06c2203ed) +PRISM [x86_64-linux] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Prism fails to parse this code ~~~ruby <<A; %Q A #{<<B} B ~~~ Parse error: ~~~ a.rb:4: syntax error found (SyntaxError) 2 | A 3 | #{<<B}
4 | B | ^ unexpected constant, expecting end-of-input
`B` at line 4 appears twice in lex result:
~~~ruby
Prism.lex('<<A; %Q
A
#{<<B}
B
').value
#=>
[[HEREDOC_START(1,0)-(1,3)("<<A"), 1],
[HEREDOC_END(2,0)-(3,0)("A\n"), 2],
[SEMICOLON(1,3)-(1,4)(";"), 1],
[STRING_BEGIN(1,5)-(2,0)("%Q\n"), 1],
[EMBEXPR_BEGIN(3,0)-(3,2)("\#{"), 1],
[HEREDOC_START(3,2)-(3,5)("<<B"), 1],
[HEREDOC_END(4,0)-(5,0)("B\n"), 2], # B\n here
[EMBEXPR_END(3,5)-(3,6)("}"), 2],
[STRING_END(3,6)-(4,0)("\n"), 2],
[CONSTANT(4,0)-(4,1)("B"), 2], # Same B again here
[NEWLINE(4,1)-(5,0)("\n"), 1],
[EOF(4,1)-(5,0)("\n"), 1]]