Evaluate lazy signatures hidden by prepended methods - #2709
Open
KaanOzkan wants to merge 1 commit into
Open
Conversation
KaanOzkan
force-pushed
the
ko-evaluate-lazy-signatures
branch
from
September 1, 2026 13:42
de2ffad to
a80a075
Compare
KaanOzkan
force-pushed
the
ko-evaluate-lazy-signatures
branch
from
September 2, 2026 13:23
a80a075 to
cabcc8d
Compare
KaanOzkan
force-pushed
the
ko-evaluate-lazy-signatures
branch
2 times, most recently
from
September 2, 2026 13:50
01d271e to
0b88b2a
Compare
When `prepend` places a wrapper before a method whose `sig` remains
pending, looking up the wrapper returns no signature. Query the
underlying method to evaluate the pending `sig`, then query the wrapper
again after Sorbet Runtime associates the signature with it.
module Wrapper
def call(...) = super
end
class Foo
extend T::Sig
sig { params(value: String).returns(String) }
def call(value) = value
prepend Wrapper
end
method = Foo.instance_method(:call)
# Before: signature_of(method) # => nil
# After: signature_of(method) # => signature with (String) -> String
KaanOzkan
force-pushed
the
ko-evaluate-lazy-signatures
branch
from
September 2, 2026 13:56
0b88b2a to
bf8b85e
Compare
KaanOzkan
marked this pull request as ready for review
September 2, 2026 15:00
Member
|
Out of curiosity, what happens if the prepended method doesn't match the arity of the super method? module Wrapper
def foo(a, b, c)
super(a + b, c)
end
end
class Bar
prepend Wrapper
#: (Integer, Integer) -> Integer
def foo(a, b)
a + b
end
end |
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.
Motivation
Fixes #2710
When
prependplaces a wrapper before a method whosesigremainspending, looking up the wrapper returns no signature.
Implementation
Query the underlying method to evaluate the pending
sigusingT::Utils.signature_forMethod, then query the wrapper again aftersorbet-runtimeassociates the signature with it.Tests
On top of automated tests, tested on Core