Support finding signatures through prepended methods - #2706
Conversation
f7dbd97 to
f141140
Compare
| # Looking up the original `Example#foo` evaluates its `sig`. Because `Wrapper` | ||
| # was prepended, Ruby now resolves `Example#foo` to `Wrapper#foo`, so Sorbet | ||
| # stores the signature for `Wrapper#foo`. The first pass causes the store; the | ||
| # second pass finds `Example#foo`'s signature on `Wrapper#foo`. |
There was a problem hiding this comment.
This comment is too hard-coded to the prepend case, but this implementation doesn't do anything to limit to prepended modules (and it's surprisingly difficult to identify them)
There was a problem hiding this comment.
Added a precursor to the comment, wdyt?
There was a problem hiding this comment.
I also think this comment could focus more on the purpose of the method rather than describing the implementation. Not a blocker.
| current_method = current_method.super_method | ||
| end | ||
|
|
||
| return nil if pass.zero? && !T::Utils.signature_for_method(method) |
There was a problem hiding this comment.
I wanted to make it faster in the normal case and return early, new version should be easier to understand
f141140 to
dfe8fab
Compare
dfe8fab to
ab2cb42
Compare
|
This is more difficult than I originally thought because walking the entire class Parent
#: (String) -> String
def foo(value) = value
end
class Child < Parent
def foo(value, suffix) = ""
end
foo = Child.instance_method(:foo)
# Before: signature_of(foo) # => nil
# Current PR: signature_of(foo) # => Parent#foo's signature (incorrect)I’m looking for a clean way to support prepended methods without changing this behavior. |
ab2cb42 to
604a3a5
Compare
604a3a5 to
2b750a5
Compare
2b750a5 to
776c8ba
Compare
Motivation
Resolves #2705
Implementation
Find signatures hidden by
prependby walkingsuper_methodthrough prepended ancestor positions and stopping at the first ordinary implementation.This requires a few things:
lookup_from) because a wrapper-owned method does not retain that scope.sigmay register it under the wrapper that was already inspected.For example in this case
lookup_fromlets us identifyWrapperas prepended, so we inspectChild#foo, and stop before incorrectly falling through toParent#foo.Tests
TBD on Core