diff --git a/load.c b/load.c index 50cc549b2e6..f1f85597642 100644 --- a/load.c +++ b/load.c @@ -395,8 +395,11 @@ get_loaded_features_index(const rb_box_t *box) rb_ary_store(features, i, as_str); features_index_add(box, as_str, INT2FIX(i)); } - /* The user modified $LOADED_FEATURES, so we should restore the changes. */ - if (!rb_ary_shared_with_p(features, box->loaded_features)) { + /* The user modified $LOADED_FEATURES, so we should restore the changes. + * A frozen array is never shared, so this check always fires for one. + * Let rb_provide_feature() report the freeze instead. */ + if (!OBJ_FROZEN(box->loaded_features) && + !rb_ary_shared_with_p(features, box->loaded_features)) { rb_ary_replace(box->loaded_features, features); } reset_loaded_features_snapshot(box); diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb index 9456dadbcb7..80c66d11fb7 100644 --- a/test/ruby/test_require.rb +++ b/test/ruby/test_require.rb @@ -537,6 +537,11 @@ class TestRequire < Test::Unit::TestCase bug3756) end + def test_frozen_loaded_features_while_rebuilding_index + assert_in_out_err(['-e', '$LOADED_FEATURES << "dummy.rb"; $LOADED_FEATURES.freeze; require "erb"'], "", + [], /\$LOADED_FEATURES is frozen; cannot append feature \(RuntimeError\)$/) + end + def test_race_exception bug5754 = '[ruby-core:41618]' path = nil