summaryrefslogtreecommitdiff
path: root/spec/ruby/language/string_spec.rb
diff options
context:
space:
mode:
authorÉtienne Barrié <etienne.barrie@gmail.com>2023-12-01 11:33:00 +0100
committerJean Boussier <jean.boussier@gmail.com>2024-03-19 09:26:49 +0100
commit12be40ae6be78ac41e8e3f3c313cc6f63e7fa6c4 (patch)
treef6b81fac770da6b705557623224dbf9b9c2d2847 /spec/ruby/language/string_spec.rb
parent86b15316a748a579dd4fd4df42b6db42accebdc2 (diff)
Implement chilled strings
[Feature #20205] As a path toward enabling frozen string literals by default in the future, this commit introduce "chilled strings". From a user perspective chilled strings pretend to be frozen, but on the first attempt to mutate them, they lose their frozen status and emit a warning rather than to raise a `FrozenError`. Implementation wise, `rb_compile_option_struct.frozen_string_literal` is no longer a boolean but a tri-state of `enabled/disabled/unset`. When code is compiled with frozen string literals neither explictly enabled or disabled, string literals are compiled with a new `putchilledstring` instruction. This instruction is identical to `putstring` except it marks the String with the `STR_CHILLED (FL_USER3)` and `FL_FREEZE` flags. Chilled strings have the `FL_FREEZE` flag as to minimize the need to check for chilled strings across the codebase, and to improve compatibility with C extensions. Notes: - `String#freeze`: clears the chilled flag. - `String#-@`: acts as if the string was mutable. - `String#+@`: acts as if the string was mutable. - `String#clone`: copies the chilled flag. Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
Diffstat (limited to 'spec/ruby/language/string_spec.rb')
-rw-r--r--spec/ruby/language/string_spec.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/spec/ruby/language/string_spec.rb b/spec/ruby/language/string_spec.rb
index f2764eada0..1a1cd35850 100644
--- a/spec/ruby/language/string_spec.rb
+++ b/spec/ruby/language/string_spec.rb
@@ -232,8 +232,8 @@ describe "Ruby String literals" do
end
it "produce different objects for literals with the same content in different files if the other file doesn't have the comment" do
- frozen_literals_by_default = eval("'test'").frozen?
- ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_no_comment.rb")).chomp.should == (!frozen_literals_by_default).to_s
+ frozen_string_literal = "test".frozen? && "test".equal?("test")
+ ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_no_comment.rb")).chomp.should == (!frozen_string_literal).to_s
end
it "produce different objects for literals with the same content in different files if they have different encodings" do