Remove SortedSet autoload and set/sorted_set

Implements [Feature #21287]
This commit is contained in:
Jeremy Evans 2025-04-27 11:21:50 -07:00
parent a7ef9a44a6
commit c52f4eea56
Notes: git 2025-05-20 04:34:46 +00:00
6 changed files with 14 additions and 68 deletions

View File

@ -105,6 +105,11 @@ The following bundled gems are updated.
[[Feature #21258]]
* With the move of `Set` from stdlib to core class, `set/sorted_set.rb` has
been removed, and `SortedSet` is no longer an autoloaded constant. Please
install the `sorted_set` gem and `require 'sorted_set'` to use `SortedSet`.
[[Feature #21287]]
## C API updates
* IO
@ -130,3 +135,4 @@ The following bundled gems are updated.
[Bug #21049]: https://bugs.ruby-lang.org/issues/21049
[Feature #21216]: https://bugs.ruby-lang.org/issues/21216
[Feature #21258]: https://bugs.ruby-lang.org/issues/21258
[Feature #21287]: https://bugs.ruby-lang.org/issues/21287

View File

@ -1,6 +0,0 @@
begin
require 'sorted_set'
rescue ::LoadError
raise "The `SortedSet` class has been extracted from the `set` library. " \
"You must use the `sorted_set` gem or other alternatives."
end

View File

@ -26,8 +26,6 @@ module Kernel
private :pp
end
autoload :SortedSet, 'set/sorted_set'
module Enumerable
# Makes a set from the enumerable object with given arguments.
def to_set(klass = Set, *args, &block)

View File

@ -1,11 +1,13 @@
require_relative '../../../spec_helper'
describe "SortedSet" do
it "raises error including message that it has been extracted from the set stdlib" do
-> {
SortedSet
}.should raise_error(RuntimeError) { |e|
e.message.should.include?("The `SortedSet` class has been extracted from the `set` library")
}
ruby_version_is ""..."3.5" do
it "raises error including message that it has been extracted from the set stdlib" do
-> {
SortedSet
}.should raise_error(RuntimeError) { |e|
e.message.should.include?("The `SortedSet` class has been extracted from the `set` library")
}
end
end
end

View File

@ -1,9 +0,0 @@
Object.instance_exec do
# Remove the constant to cancel autoload that would be fired by
# `class SortedSet` and cause circular require.
remove_const :SortedSet if const_defined?(:SortedSet)
end
class SortedSet < Set
# ...
end

View File

@ -1,45 +0,0 @@
# frozen_string_literal: false
require 'test/unit'
require 'set'
class TC_SortedSet < Test::Unit::TestCase
def base_dir
"#{__dir__}/../lib"
end
def assert_runs(ruby, options: nil)
options = ['-I', base_dir, *options]
r = system(RbConfig.ruby, *options, '-e', ruby)
assert(r)
end
def test_error
assert_runs <<~RUBY
require "set"
r = begin
puts SortedSet.new
rescue Exception => e
e.message
end
raise r unless r.match?(/has been extracted/)
RUBY
end
def test_ok_with_gem
assert_runs <<~RUBY, options: ['-I', "#{__dir__}/fixtures/fake_sorted_set_gem"]
require "set"
var = SortedSet.new.to_s
RUBY
end
def test_ok_require
assert_runs <<~RUBY, options: ['-I', "#{__dir__}/fixtures/fake_sorted_set_gem"]
require "set"
require "sorted_set"
var = SortedSet.new.to_s
RUBY
end
end