Project

General

Profile

Bug #14475

String de-duplication is broken in files with frozen_string_literal: true

Added by sam.saffron (Sam Saffron) over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
2.5.0, 2.6.0
[ruby-core:85542]

Description

Create 2 files:

test.rb

$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'frozen'

puts frozen.object_id
puts frozen.object_id

frozen.rb

# frozen_string_literal: true

A = "a"
def frozen
  -"#{A}"
end

Run test.rb

% ruby test.rb
70189973179400
70189973179260

Change to # frozen_string_literal: false

And you get

70189973181360
70189973181360

So something is over-optimising here, fix should be backported to 2.5.0 imo.


Related issues

Related to Ruby master - Feature #14478: String #uminus should de-dupe unconditionallyClosedActions

Also available in: Atom PDF