jruby icon indicating copy to clipboard operation
jruby copied to clipboard

Line number is incorrect for interpolation inside heredoc

Open judofyr opened this issue 3 years ago • 6 comments

Script:

def __tilt_4000
<<TILT1596320670.chomp
<html>
<body>
<h1>Hey #{name}!</h1>
TILT1596320670
end

__tilt_4000

Environment Information

$ jruby -v
jruby 9.3.3.0 (2.6.8) 2022-01-19 b26de1f5c5 OpenJDK 64-Bit Server VM 18+0 on 18+0 +jit [darwin-x86_64]
$ uname -a
Darwin sam.home 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64 x86_64

Expected Behavior

The error is reported at line 5:

$ /usr/bin/ruby t.rb
t.rb:5:in `__tilt_4000': undefined local variable or method `name' for main:Object (NameError)
	from t.rb:9:in `<main>'

Actual Behavior

The error is reported where the heredoc starts:

$ jruby t.rb
NameError: undefined local variable or method `name' for main:Object
  __tilt_4000 at t.rb:2
       <main> at t.rb:9

judofyr avatar Jul 18 '22 20:07 judofyr

method_missing is issuing this but the #{name} processing must not be emitting a linenum instr. I think. Also affects 9.4.x

enebo avatar Feb 02 '23 18:02 enebo

Still valid in both 9.3 and 9.4 HEAD, but won't be fixed for 9.3.11.

headius avatar Sep 10 '23 20:09 headius

@judofyr Dunno if you are still out there, but this would be a great addition to ruby/spec. Could you write up a quick PR?

Moving to 9.5 since this probably will get fixed in the move to Prism.

headius avatar Feb 09 '24 18:02 headius

@judofyr Dunno if you are still out there, but this would be a great addition to ruby/spec. Could you write up a quick PR?

Moving to 9.5 since this probably will get fixed in the move to Prism.

Like this https://github.com/ruby/spec/pull/1135?

judofyr avatar Feb 10 '24 08:02 judofyr

While writing the test I also discovered that it only happens if you have the .chomp there. Without it it passes.

judofyr avatar Feb 10 '24 08:02 judofyr

@judofyr:

Like this ruby/spec#1135?

Great! I will comment there with some small suggestions.

While writing the test I also discovered that it only happens if you have the .chomp there.

Ah interesting. So it is wiping out the line numbers in the heredoc when it has other code following the opening tag. Perhaps that will help @enebo to fix this.

Thank you!

headius avatar Feb 10 '24 18:02 headius