Skip to content

Commit 2ca42ad

Browse files
etiennebarriebyrootnobu
authored andcommitted
Show where mutated chilled strings were allocated
[Feature #20205] The warning now suggests running with --debug-frozen-string-literal: ``` test.rb:3: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information) ``` When using --debug-frozen-string-literal, the location where the string was created is shown: ``` test.rb:3: warning: literal string will be frozen in the future test.rb:1: info: the string was created here ``` When resurrecting strings and debug mode is not enabled, the overhead is a simple FL_TEST_RAW. When mutating chilled strings and deprecation warnings are not enabled, the overhead is a simple warning category enabled check. Co-authored-by: Jean Boussier <[email protected]> Co-authored-by: Nobuyoshi Nakada <[email protected]> Co-authored-by: Jean Boussier <[email protected]>
1 parent 51bda14 commit 2ca42ad

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

command_line/fixtures/debug_info.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# frozen_string_literal: true
21
a = 'string'
32
b = a
43
c = b

command_line/frozen_strings_spec.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,18 @@
5757

5858
describe "The --debug flag produces" do
5959
it "debugging info on attempted frozen string modification" do
60-
error_str = ruby_exe(fixture(__FILE__, 'debug_info.rb'), options: '--debug', args: "2>&1")
60+
error_str = ruby_exe(fixture(__FILE__, 'debug_info.rb'), options: '--enable-frozen-string-literal --debug', args: "2>&1")
6161
error_str.should include("can't modify frozen String")
6262
error_str.should include("created at")
63-
error_str.should include("command_line/fixtures/debug_info.rb:2")
63+
error_str.should include("command_line/fixtures/debug_info.rb:1")
64+
end
65+
66+
guard -> { ruby_version_is "3.4" and !"test".frozen? } do
67+
it "debugging info on mutating chilled string" do
68+
error_str = ruby_exe(fixture(__FILE__, 'debug_info.rb'), options: '-w --debug', args: "2>&1")
69+
error_str.should include("literal string will be frozen in the future")
70+
error_str.should include("the string was created here")
71+
error_str.should include("command_line/fixtures/debug_info.rb:1")
72+
end
6473
end
6574
end

0 commit comments

Comments
 (0)