Project

General

Profile

Actions

Bug #13540

closed

can't set length of shared string (RuntimeError) when interpolating __FILE__ in a heredoc

Added by kylerippey (Kyle Rippey) about 7 years ago. Updated almost 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
[ruby-core:80987]

Description

There appears to be a bug in Ruby 2.4.0 and 2.4.1 when interpolating __FILE__ inside of a heredoc. In fact, no code in this file executes when this interpolation is present. Almost as if it's a syntax error, but it's reported as a RuntimeError.

# Works in Ruby 2.3 and 2.4
puts "#{__FILE__}"

# Works in Ruby 2.3 and 2.4
x = __FILE__
puts <<~HEREDOC
  #{x}
HEREDOC

# Works in Ruby 2.3
# Raises exception in Ruby 2.4: can't set length of shared string (RuntimeError)
puts <<~HEREDOC
  #{__FILE__}
HEREDOC
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0