-
Notifications
You must be signed in to change notification settings - Fork 194
Description
Background
The backslash / continued line \
does not work as intended on TruffleRuby when it's used at the end of a line within a squiggly heredoc.
Take this example:
x = <<~HERE
a
b\
c
HERE
puts x
Expected behaviour
MRI removes both the newline and indentation of the next line.
➜ chruby 2.7.2
➜ ruby test.rb
"a\nbc\n"
Actual behaviour on TruffleRuby
On TruffleRuby, no newline is added, but the indentation of the next line remains.
➜ chruby truffleruby-jvm
➜ ruby test.rb
"a\nb c\n"
What we think is happening on TruffleRuby
Presumably, what we think happens is that TruffleRuby first removes the newline before dedenting.
Here is an example if what I mean:
x = <<~HERE
a
b\
c
HERE
In this example, what happens first is TruffleRuby sees the backslash and then removes the new line between b
and c
, making it:
a
b c
After that, it dedents the string:
a
b c
Returning "a\nb c\n"
What is supposed to happen
What is happening in MRI is the opposite.
The dedenting happens before removal of the backslash and newline:
x = <<~HERE
a
b\
c
HERE
Dedent:
a
b\
c
Remove newline and backslash:
a
bc
Returning: "a\nbc\n"
More information about the issue
-
There is no Ruby spec for this case, but I've created a spec on this draft PR.
-
Despite having no Ruby spec for this, there is a test on
TestSyntax.rb
for it calledtest_dedented_heredoc_continued_line
. The test is currently excluded and not run on TruffleRuby. -
There is also an old MRI issue for this behaviour.
-
JRuby fixed this issue among several other issues in this commit.
-
The issue seems to be within the
RubyLexer.java
and more specifically thepublic void heredoc_dedent()
function. But I don't have any context into how that works yet, which leads me to...
Questions for the TruffleRuby team:
- Is there any truth to what seems to be the problem (as explained above)?
- Can you point me to the place where the issue might be?