Add signature matching for positional parameters #2541
Merged
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
Step towards #2363
To determine which signature overload to show, we are going to need to match a declaration signature to the arguments of a method call. Doing it all in a single PR felt a bit too complex, so this PR only adds the method
matches?
toSignature
and only implements matching for positional arguments. I will follow up with the implementation for keyword arguments.Implementation
For matching positional arguments, we essentially need to check if the number of arguments in the method call are within the range of possible arguments that the method accepts. For example:
There are also special rules for splats and forwarding arguments. In general, these are not statically analyzable and we just bail out saying that the signature does match, but there are a few scenarios where we can do at least partial matching. For example:
See the tests for more examples.
Automated Tests
Added tests.