diff --git a/lib/rbs/prototype/runtime/value_object_generator.rb b/lib/rbs/prototype/runtime/value_object_generator.rb index 876d793dd5..f85f6cfada 100644 --- a/lib/rbs/prototype/runtime/value_object_generator.rb +++ b/lib/rbs/prototype/runtime/value_object_generator.rb @@ -99,8 +99,6 @@ def self.generatable?(target) private - CAN_CALL_KEYWORD_INIT_P = Struct.new(:tmp).respond_to?(:keyword_init?) - def build_super_class AST::Declarations::Class::Super.new(name: TypeName.parse("::Struct"), args: [untyped], location: nil) end @@ -118,21 +116,16 @@ def build_s_new [:new, :[]].map do |name| new_overloads = [] #: Array[AST::Members::MethodDefinition::Overload] - if CAN_CALL_KEYWORD_INIT_P - case @target_class.keyword_init? - when false - new_overloads << build_overload_for_positional_arguments - when true - new_overloads << build_overload_for_keyword_arguments - when nil - new_overloads << build_overload_for_positional_arguments - new_overloads << build_overload_for_keyword_arguments - else - raise - end - else + case @target_class.keyword_init? + when false + new_overloads << build_overload_for_positional_arguments + when true + new_overloads << build_overload_for_keyword_arguments + when nil new_overloads << build_overload_for_positional_arguments new_overloads << build_overload_for_keyword_arguments + else + raise end AST::Members::MethodDefinition.new( @@ -178,8 +171,6 @@ def build_overload_for_keyword_arguments # def self.keyword_init?: () -> bool? def build_s_keyword_init_p - return [] unless CAN_CALL_KEYWORD_INIT_P - return_type = @target_class.keyword_init?.nil? \ ? Types::Bases::Nil.new(location: nil) : Types::Literal.new(literal: @target_class.keyword_init?, location: nil) diff --git a/sig/prototype/runtime.rbs b/sig/prototype/runtime.rbs index 0221518be7..7d9464dfb1 100644 --- a/sig/prototype/runtime.rbs +++ b/sig/prototype/runtime.rbs @@ -64,8 +64,6 @@ module RBS def build_s_new: () -> Array[AST::Members::MethodDefinition] def build_super_class: () -> AST::Declarations::Class::Super - - CAN_CALL_KEYWORD_INIT_P: bool end class DataGenerator < ValueObjectBase diff --git a/test/rbs/runtime_prototype_test.rb b/test/rbs/runtime_prototype_test.rb index 24efac0cda..a0c89afc15 100644 --- a/test/rbs/runtime_prototype_test.rb +++ b/test/rbs/runtime_prototype_test.rb @@ -690,151 +690,77 @@ def test_struct SignatureManager.new do |manager| manager.build do |env| p = Runtime.new(patterns: ["RBS::RuntimePrototypeTest::StructInheritWithNil"], env: env, merge: false) - if Runtime::StructGenerator::CAN_CALL_KEYWORD_INIT_P - assert_write p.decls, <<~RBS - module RBS - class RuntimePrototypeTest < ::Test::Unit::TestCase - class StructInheritWithNil < ::Struct[untyped] - def self.new: (?untyped foo, ?untyped bar, ?untyped `baz?`) -> instance - | (?foo: untyped, ?bar: untyped, ?baz?: untyped) -> instance - - def self.[]: (?untyped foo, ?untyped bar, ?untyped `baz?`) -> instance - | (?foo: untyped, ?bar: untyped, ?baz?: untyped) -> instance - - def self.keyword_init?: () -> nil - - def self.members: () -> [ :foo, :bar, :baz? ] - - def members: () -> [ :foo, :bar, :baz? ] - - attr_accessor foo: untyped - - attr_accessor bar: untyped + assert_write p.decls, <<~RBS + module RBS + class RuntimePrototypeTest < ::Test::Unit::TestCase + class StructInheritWithNil < ::Struct[untyped] + def self.new: (?untyped foo, ?untyped bar, ?untyped `baz?`) -> instance + | (?foo: untyped, ?bar: untyped, ?baz?: untyped) -> instance - attr_accessor baz?: untyped - end - end - end - RBS - else - assert_write p.decls, <<~RBS - module RBS - class RuntimePrototypeTest < ::Test::Unit::TestCase - class StructInheritWithNil < ::Struct[untyped] - def self.new: (?untyped foo, ?untyped bar, ?untyped `baz?`) -> instance - | (?foo: untyped, ?bar: untyped, ?baz?: untyped) -> instance + def self.[]: (?untyped foo, ?untyped bar, ?untyped `baz?`) -> instance + | (?foo: untyped, ?bar: untyped, ?baz?: untyped) -> instance - def self.[]: (?untyped foo, ?untyped bar, ?untyped `baz?`) -> instance - | (?foo: untyped, ?bar: untyped, ?baz?: untyped) -> instance + def self.keyword_init?: () -> nil - def self.members: () -> [ :foo, :bar, :baz? ] + def self.members: () -> [ :foo, :bar, :baz? ] - def members: () -> [ :foo, :bar, :baz? ] + def members: () -> [ :foo, :bar, :baz? ] - attr_accessor foo: untyped + attr_accessor foo: untyped - attr_accessor bar: untyped + attr_accessor bar: untyped - attr_accessor baz?: untyped - end + attr_accessor baz?: untyped end end - RBS - end + end + RBS p = Runtime.new(patterns: ["RBS::RuntimePrototypeTest::StructKeywordInitTrue"], env: env, merge: false) - if Runtime::StructGenerator::CAN_CALL_KEYWORD_INIT_P - assert_write p.decls, <<~RBS - module RBS - class RuntimePrototypeTest < ::Test::Unit::TestCase - class StructKeywordInitTrue < ::Struct[untyped] - def self.new: (?foo: untyped, ?bar: untyped) -> instance - - def self.[]: (?foo: untyped, ?bar: untyped) -> instance - - def self.keyword_init?: () -> true - - def self.members: () -> [ :foo, :bar ] - - def members: () -> [ :foo, :bar ] - - attr_accessor foo: untyped + assert_write p.decls, <<~RBS + module RBS + class RuntimePrototypeTest < ::Test::Unit::TestCase + class StructKeywordInitTrue < ::Struct[untyped] + def self.new: (?foo: untyped, ?bar: untyped) -> instance - attr_accessor bar: untyped - end - end - end - RBS - else - assert_write p.decls, <<~RBS - module RBS - class RuntimePrototypeTest < ::Test::Unit::TestCase - class StructKeywordInitTrue < ::Struct[untyped] - def self.new: (?untyped foo, ?untyped bar) -> instance - | (?foo: untyped, ?bar: untyped) -> instance + def self.[]: (?foo: untyped, ?bar: untyped) -> instance - def self.[]: (?untyped foo, ?untyped bar) -> instance - | (?foo: untyped, ?bar: untyped) -> instance + def self.keyword_init?: () -> true - def self.members: () -> [ :foo, :bar ] + def self.members: () -> [ :foo, :bar ] - def members: () -> [ :foo, :bar ] + def members: () -> [ :foo, :bar ] - attr_accessor foo: untyped + attr_accessor foo: untyped - attr_accessor bar: untyped - end + attr_accessor bar: untyped end end - RBS - end + end + RBS p = Runtime.new(patterns: ["RBS::RuntimePrototypeTest::StructKeywordInitFalse"], env: env, merge: false) - if Runtime::StructGenerator::CAN_CALL_KEYWORD_INIT_P - assert_write p.decls, <<~RBS - module RBS - class RuntimePrototypeTest < ::Test::Unit::TestCase - class StructKeywordInitFalse < ::Struct[untyped] - def self.new: (?untyped foo, ?untyped bar) -> instance - - def self.[]: (?untyped foo, ?untyped bar) -> instance - - def self.keyword_init?: () -> false - - def self.members: () -> [ :foo, :bar ] - - def members: () -> [ :foo, :bar ] - - attr_accessor foo: untyped + assert_write p.decls, <<~RBS + module RBS + class RuntimePrototypeTest < ::Test::Unit::TestCase + class StructKeywordInitFalse < ::Struct[untyped] + def self.new: (?untyped foo, ?untyped bar) -> instance - attr_accessor bar: untyped - end - end - end - RBS - else - assert_write p.decls, <<~RBS - module RBS - class RuntimePrototypeTest < ::Test::Unit::TestCase - class StructKeywordInitFalse < ::Struct[untyped] - def self.new: (?untyped foo, ?untyped bar) -> instance - | (?foo: untyped, ?bar: untyped) -> instance + def self.[]: (?untyped foo, ?untyped bar) -> instance - def self.[]: (?untyped foo, ?untyped bar) -> instance - | (?foo: untyped, ?bar: untyped) -> instance + def self.keyword_init?: () -> false - def self.members: () -> [ :foo, :bar ] + def self.members: () -> [ :foo, :bar ] - def members: () -> [ :foo, :bar ] + def members: () -> [ :foo, :bar ] - attr_accessor foo: untyped + attr_accessor foo: untyped - attr_accessor bar: untyped - end + attr_accessor bar: untyped end end - RBS - end + end + RBS p = Runtime.new(patterns: ["RBS::RuntimePrototypeTest::StructDirectInherited"], env: env, merge: false) assert_write p.decls, <<~RBS @@ -849,74 +775,72 @@ class StructDirectInherited < ::Struct[untyped] end end - if RUBY_VERSION >= '3.2' - class DataInherit < Data.define(:foo, :bar, :baz?) - end - DataConst = Data.define(:foo, :bar) - class DataDirectInherit < Data - end + class DataInherit < Data.define(:foo, :bar, :baz?) + end + DataConst = Data.define(:foo, :bar) + class DataDirectInherit < Data + end - def test_data - SignatureManager.new do |manager| - manager.build do |env| - p = Runtime.new(patterns: ["RBS::RuntimePrototypeTest::DataInherit"], env: env, merge: false) - assert_write p.decls, <<~RBS - module RBS - class RuntimePrototypeTest < ::Test::Unit::TestCase - class DataInherit < ::Data - def self.new: (untyped foo, untyped bar, untyped `baz?`) -> instance - | (foo: untyped, bar: untyped, baz?: untyped) -> instance + def test_data + SignatureManager.new do |manager| + manager.build do |env| + p = Runtime.new(patterns: ["RBS::RuntimePrototypeTest::DataInherit"], env: env, merge: false) + assert_write p.decls, <<~RBS + module RBS + class RuntimePrototypeTest < ::Test::Unit::TestCase + class DataInherit < ::Data + def self.new: (untyped foo, untyped bar, untyped `baz?`) -> instance + | (foo: untyped, bar: untyped, baz?: untyped) -> instance - def self.[]: (untyped foo, untyped bar, untyped `baz?`) -> instance - | (foo: untyped, bar: untyped, baz?: untyped) -> instance + def self.[]: (untyped foo, untyped bar, untyped `baz?`) -> instance + | (foo: untyped, bar: untyped, baz?: untyped) -> instance - def self.members: () -> [ :foo, :bar, :baz? ] + def self.members: () -> [ :foo, :bar, :baz? ] - def members: () -> [ :foo, :bar, :baz? ] + def members: () -> [ :foo, :bar, :baz? ] - attr_reader foo: untyped + attr_reader foo: untyped - attr_reader bar: untyped + attr_reader bar: untyped - attr_reader baz?: untyped - end + attr_reader baz?: untyped end end - RBS + end + RBS - p = Runtime.new(patterns: ["RBS::RuntimePrototypeTest::DataConst"], env: env, merge: false) - assert_write p.decls, <<~RBS - module RBS - class RuntimePrototypeTest < ::Test::Unit::TestCase - class DataConst < ::Data - def self.new: (untyped foo, untyped bar) -> instance - | (foo: untyped, bar: untyped) -> instance + p = Runtime.new(patterns: ["RBS::RuntimePrototypeTest::DataConst"], env: env, merge: false) + assert_write p.decls, <<~RBS + module RBS + class RuntimePrototypeTest < ::Test::Unit::TestCase + class DataConst < ::Data + def self.new: (untyped foo, untyped bar) -> instance + | (foo: untyped, bar: untyped) -> instance - def self.[]: (untyped foo, untyped bar) -> instance - | (foo: untyped, bar: untyped) -> instance + def self.[]: (untyped foo, untyped bar) -> instance + | (foo: untyped, bar: untyped) -> instance - def self.members: () -> [ :foo, :bar ] + def self.members: () -> [ :foo, :bar ] - def members: () -> [ :foo, :bar ] + def members: () -> [ :foo, :bar ] - attr_reader foo: untyped + attr_reader foo: untyped - attr_reader bar: untyped - end + attr_reader bar: untyped end end - RBS + end + RBS - p = Runtime.new(patterns: ["RBS::RuntimePrototypeTest::DataDirectInherit"], env: env, merge: false) - assert_write p.decls, <<~RBS - module RBS - class RuntimePrototypeTest < ::Test::Unit::TestCase - class DataDirectInherit < ::Data - end + p = Runtime.new(patterns: ["RBS::RuntimePrototypeTest::DataDirectInherit"], env: env, merge: false) + assert_write p.decls, <<~RBS + module RBS + class RuntimePrototypeTest < ::Test::Unit::TestCase + class DataDirectInherit < ::Data end end - RBS - end + end + RBS end end end diff --git a/test/rbs/test/runtime_test_test.rb b/test/rbs/test/runtime_test_test.rb index ad8b969c30..f0f98de474 100644 --- a/test/rbs/test/runtime_test_test.rb +++ b/test/rbs/test/runtime_test_test.rb @@ -2,8 +2,6 @@ require "rbs/test" require "logger" -return unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0') - class RBS::Test::RuntimeTestTest < Test::Unit::TestCase omit_on_truffle_ruby! "`rbs test` relies on `TracePoint` `:end` event, which is not supported on TruffleRuby" omit_on_jruby! "`rbs test` relies on `TracePoint` `:end` event, which is not supported on JRuby" diff --git a/test/stdlib/Regexp_test.rb b/test/stdlib/Regexp_test.rb index 80b9f5cd89..9854936471 100644 --- a/test/stdlib/Regexp_test.rb +++ b/test/stdlib/Regexp_test.rb @@ -51,14 +51,6 @@ def test_compile assert_send_type '(string, int | string | bool | nil) -> Regexp', Regexp, :compile, pattern, options - # In older versions of ruby, `Regexp.{new,compile}` could take an additional third argument, - # which indicated "no encoding". Due to weirdnesses with how keyword arguments are passed - # around in Ruby, along with how `compile` is registered internally, the `timeout: _ToF?` - # argument is interpreted as this optional third argument in older versions. So, to prevent - # any issues, this `next` skips it. Note that this issue doesn't occur in `test_initialize` - # because the implicit argument passing isn't done. - next if RUBY_VERSION < '3.3' - with_float(12.34).and_nil do |timeout| assert_send_type '(string, int | string | bool | nil, timeout: _ToF?) -> Regexp', Regexp, :compile, pattern, options, timeout: timeout @@ -149,8 +141,6 @@ def (toregexp = BlankSlate.new).to_regexp = /a/ end def test_timeout - omit_if RUBY_VERSION < '3.2' - begin old_timeout = Regexp.timeout @@ -167,8 +157,6 @@ def test_timeout end def test_timeout= - omit_if RUBY_VERSION < '3.2' - begin old_timeout = Regexp.timeout diff --git a/test/stdlib/RubyVM_test.rb b/test/stdlib/RubyVM_test.rb index 71d5f42c2e..c478e5fa80 100644 --- a/test/stdlib/RubyVM_test.rb +++ b/test/stdlib/RubyVM_test.rb @@ -21,11 +21,9 @@ def test_of RubyVM::AbstractSyntaxTree, :of, method(:test_of) end - if RUBY_VERSION >= '3.2' - def test_node_id_for_backtrace_location - assert_send_type "(::Thread::Backtrace::Location backtrace_location) -> ::Integer", - RubyVM::AbstractSyntaxTree, :node_id_for_backtrace_location, caller_locations[0] - end + def test_node_id_for_backtrace_location + assert_send_type "(::Thread::Backtrace::Location backtrace_location) -> ::Integer", + RubyVM::AbstractSyntaxTree, :node_id_for_backtrace_location, caller_locations[0] end end @@ -66,16 +64,14 @@ def test_locations end end - if RUBY_VERSION >= '3.2' - def test_tokens - assert_send_type "() -> ::Array[[ ::Integer, ::Symbol, ::String, [ ::Integer, ::Integer, ::Integer, ::Integer ] ]]?", - RubyVM::AbstractSyntaxTree.parse("1 + 2", keep_tokens: true), :tokens - end + def test_tokens + assert_send_type "() -> ::Array[[ ::Integer, ::Symbol, ::String, [ ::Integer, ::Integer, ::Integer, ::Integer ] ]]?", + RubyVM::AbstractSyntaxTree.parse("1 + 2", keep_tokens: true), :tokens + end - def test_all_tokens - assert_send_type "() -> ::Array[[ ::Integer, ::Symbol, ::String, [ ::Integer, ::Integer, ::Integer, ::Integer ] ]]?", - RubyVM::AbstractSyntaxTree.parse("1 + 2", keep_tokens: true), :all_tokens - end + def test_all_tokens + assert_send_type "() -> ::Array[[ ::Integer, ::Symbol, ::String, [ ::Integer, ::Integer, ::Integer, ::Integer ] ]]?", + RubyVM::AbstractSyntaxTree.parse("1 + 2", keep_tokens: true), :all_tokens end def test_children diff --git a/test/stdlib/String_test.rb b/test/stdlib/String_test.rb index 7a42d481f0..988a625f36 100644 --- a/test/stdlib/String_test.rb +++ b/test/stdlib/String_test.rb @@ -323,8 +323,6 @@ def test_b end def test_byteindex - omit_if RUBY_VERSION < '3.2' - with_string('e').and /e/ do |pattern| assert_send_type '(Regexp | string) -> Integer', 'hello', :byteindex, pattern @@ -341,8 +339,6 @@ def test_byteindex end def test_byterindex - omit_if RUBY_VERSION < '3.2' - with_string('e').and /e/ do |pattern| assert_send_type '(Regexp | string) -> Integer', 'hello', :byterindex, pattern @@ -389,32 +385,22 @@ def test_byteslice end def test_bytesplice - omit_if(RUBY_VERSION < '3.2', 'String#bytesplice was added in 3.2') - - # In 3.3 and onwards (and backported to 3.2.16), the return type is `self`. This variable - # is in case the test suite is run in a version under 3.2.16; tests for the variants only - # supported in 3.3 and onwards use `self`. If we ever stop supporting 3.2, we can remove this. - with_string ', world! :-D' do |string| assert_send_type "(Integer, Integer, string) -> String", +'hello', :bytesplice, 1, 2, string - if RUBY_VERSION >= "3.3.0" - with_int 1 do |start| - assert_send_type '(int, Integer, string, Integer, Integer) -> String', - +'hello', :bytesplice, start, 2, string, 3, 4 - end + with_int 1 do |start| + assert_send_type '(int, Integer, string, Integer, Integer) -> String', + +'hello', :bytesplice, start, 2, string, 3, 4 end with_range with_int(1).and_nil, with_int(2).and_nil do |range| assert_send_type "(range[int?], string) -> String", +'hello', :bytesplice, range, string - if RUBY_VERSION >= '3.3.0' - with_range with_int(3).and_nil, with_int(4).and_nil do |string_range| - assert_send_type '(range[int?], string, range[int?]) -> String', - +'hello', :bytesplice, range, string, string_range - end + with_range with_int(3).and_nil, with_int(4).and_nil do |string_range| + assert_send_type '(range[int?], string, range[int?]) -> String', + +'hello', :bytesplice, range, string, string_range end end end @@ -574,7 +560,6 @@ def test_count end def test_dedup - omit_if RUBY_VERSION < '3.2.0' test_uneg :dedup end diff --git a/test/stdlib/Warning_test.rb b/test/stdlib/Warning_test.rb index 809da4f28b..d02e3ada84 100644 --- a/test/stdlib/Warning_test.rb +++ b/test/stdlib/Warning_test.rb @@ -1,7 +1,6 @@ require_relative "test_helper" -WARNING_CATEGORIES = %i[deprecated experimental] -WARNING_CATEGORIES << :performance if RUBY_VERSION >= '3.3' +WARNING_CATEGORIES = %i[deprecated experimental performance] class WarningSingletonTest < Test::Unit::TestCase include TestHelper