The attached patch fails in an IRB test.
I'm not sure about this prompt transition, should this be fixed as expected?
As the line 004 ends the heredoc C but is inside %W[, isn't ] ok here?
I've opend a pull request to fix irb's test. Changes expected prompt and target code to avoid this bug in ruby 2.7~3.2. https://github.com/ruby/irb/pull/558