Skip to content

Commit

Permalink
Fix --debug-frozen-string-literal to not apply `--disable-frozen-st…
Browse files Browse the repository at this point in the history
…ring-literal`

[Feature #20205]

This was an undesired side effect. Now that this value is a triplet, we can't
assume it's disabled by default.
  • Loading branch information
byroot committed Jun 24, 2024
1 parent 9cfc136 commit 95ffcd3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ void rb_warning_category_update(unsigned int mask, unsigned int bits);
#define DEFINE_DEBUG_FEATURE(bit) feature_debug_##bit
enum feature_flag_bits {
EACH_FEATURES(DEFINE_FEATURE, COMMA),
DEFINE_FEATURE(frozen_string_literal_set),
feature_debug_flag_first,
#if defined(RJIT_FORCE_ENABLE) || !USE_YJIT
DEFINE_FEATURE(jit) = feature_rjit,
Expand Down Expand Up @@ -189,6 +190,7 @@ enum {
COMPILATION_FEATURES = (
0
| FEATURE_BIT(frozen_string_literal)
| FEATURE_BIT(frozen_string_literal_set)
| FEATURE_BIT(debug_frozen_string_literal)
),
DEFAULT_FEATURES = (
Expand All @@ -197,6 +199,7 @@ enum {
& ~FEATURE_BIT(gems)
#endif
& ~FEATURE_BIT(frozen_string_literal)
& ~FEATURE_BIT(frozen_string_literal_set)
& ~feature_jit_mask
)
};
Expand Down Expand Up @@ -1033,6 +1036,9 @@ feature_option(const char *str, int len, void *arg, const unsigned int enable)

found:
FEATURE_SET_TO(*argp, mask, (mask & enable));
if (NAME_MATCH_P("frozen_string_literal", str, len)) {
FEATURE_SET_TO(*argp, FEATURE_BIT(frozen_string_literal_set), FEATURE_BIT(frozen_string_literal_set));
}
return;
}

Expand Down Expand Up @@ -2437,7 +2443,10 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
#define SET_COMPILE_OPTION(h, o, name) \
rb_hash_aset((h), ID2SYM(rb_intern_const(#name)), \
RBOOL(FEATURE_SET_P(o->features, name)))
SET_COMPILE_OPTION(option, opt, frozen_string_literal);

if (FEATURE_SET_P(opt->features, frozen_string_literal_set)) {
SET_COMPILE_OPTION(option, opt, frozen_string_literal);
}
SET_COMPILE_OPTION(option, opt, debug_frozen_string_literal);
rb_funcallv(rb_cISeq, rb_intern_const("compile_option="), 1, &option);
#undef SET_COMPILE_OPTION
Expand Down
11 changes: 11 additions & 0 deletions test/ruby/test_rubyoptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,17 @@ def test_frozen_string_literal_debug
end
end

def test_frozen_string_literal_debug_chilled_strings
code = <<~RUBY
"foo" << "bar"
RUBY
warning = ["-:1: warning: literal string will be frozen in the future"]
assert_in_out_err(["-W:deprecated"], code, [], warning)
assert_in_out_err(["-W:deprecated", "--debug-frozen-string-literal"], code, [], warning)
assert_in_out_err(["-W:deprecated", "--disable-frozen-string-literal", "--debug-frozen-string-literal"], code, [], [])
assert_in_out_err(["-W:deprecated", "--enable-frozen-string-literal", "--debug-frozen-string-literal"], code, [], ["-:1:in '<main>': can't modify frozen String: \"foo\", created at -:1 (FrozenError)"])
end

def test___dir__encoding
lang = {"LC_ALL"=>ENV["LC_ALL"]||ENV["LANG"]}
with_tmpchdir do
Expand Down

0 comments on commit 95ffcd3

Please sign in to comment.