Convert self to ClassInstance when #initialize method#2831
Merged
ksss merged 2 commits intoruby:masterfrom Jan 29, 2026
Merged
Conversation
ksss
commented
Jan 29, 2026
|
|
||
|
|
||
| def test_new | ||
| assert_send_type "(::OpenSSL::BN) -> OpenSSL::BN", |
Collaborator
Author
There was a problem hiding this comment.
Before the changes
Failure: test_new(OpenSSLBNSingletonTest):
Call trace does not match one of method definitions:
#<struct RBS::Test::CallTrace method_name=:new, method_call=<RBS::Test::ArgumentsReturn:@arguments: [#<OpenSSL::BN:0x00000001279b8b38>], @exit_value: #<OpenSSL::BN:0x0000000127951e10>, @exit_type: :return>, block_calls=[], block_given=false>
(self) -> ::OpenSSL::BN | (::Integer) -> ::OpenSSL::BN | (::string) -> ::OpenSSL::BN | (::string, 0 | 2 | 10 | 16) -> ::OpenSSL::BN.
<false> is not true.
/Users/ksss/src/github.com/ksss/rbs/lib/rbs/unit_test/type_assertions.rb:187:in 'block in RBS::UnitTest::TypeAssertions#assert_send_type'
/Users/ksss/src/github.com/ksss/rbs/lib/rbs/unit_test/type_assertions.rb:168:in 'RBS::UnitTest::TypeAssertions#send_setup'
/Users/ksss/src/github.com/ksss/rbs/lib/rbs/unit_test/type_assertions.rb:172:in 'RBS::UnitTest::TypeAssertions#assert_send_type'
test/stdlib/OpenSSL_test.rb:237:in 'OpenSSLBNSingletonTest#test_new'
234: end
235:
236: def test_new
=> 237: assert_send_type "(::OpenSSL::BN) -> OpenSSL::BN",
238: OpenSSL::BN, :new, OpenSSL::BN.new(3)
239: end
240: end
self with #initialize methodself to ClassInstance when #initialize method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In a class, the
#initializemethod is often copied as the type for the.newmethod.In this case, if
selfis used in the type definition, they are copied as is.As a result, a problem has been reported by @rhiroe where
selfis treated assingleton(Foo)even though it was written asselfin the context of#initialize.I aim to solve this by dynamically rewriting the type when it is copied from
#initializeto.new.Real problem
With Generics
Before
After