-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infer function parameter types from partially eta-expanded methods (backport #7316 and #7333) #7340
Conversation
Let's create a fast path for after typer, when we already know which SAM to target, and all parameter types are known Backported from b2edce8
Do more for typedFunction of eta-expanded method: keep typed method selection (fix scala/bug#9745, follow up for scala#6007) Test case taken from original PR. Backported from 64d4c24
Drop impossible error check. We always produced `numVparams` argument prototypes, so there was no way we would ever call WrongNumberOfParametersError. Backported from a9f8c14
Generalize function parameter type inference to allow any subset (including permutation) of parameters with unknown types to be inferred from the method they are applied to. Before, we required all method arguments to come from the function's vparams, in order. Example: ``` scala> def repeat(x: Int, y: String) = y * x repeat: (x: Int, y: String)String scala> val sayAaah = repeat(_, "a") sayAaah: Int => String scala> val thrice = x => repeat(3, x) thrice: String => String scala> val repeatFlip = (x, y) => repeat(y, x) repeatFlip: (String, Int) => String ``` Backported from 967ab56
ac0dbb7
to
93cd804
Compare
It's not a small diff, and touches a quite heavily used and non-trivial part of the type checker. On the other hand, the fact that it's heavily used (in 2.13, exercised by collections) gives it a good coverage. So I'm +1. |
(cherry picked from commit a38f306)
Note that I dropped one behavior change from the 2.13 version: we still report errors in bodies of functions that have params with missing types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to align 2.12 with 2.13 here.
It would be great to write a short doc describing the various changes and fixes to type inference of lambdas so that @niktrop et al can bring them into IntelliJ.
I think this is release-note worthy for 2.12.8, so that's another reason for the PR description to be updated to describe the user-facing parts. |
Backport a fix for scala/bug#9745 (#7316) and improve type inference for partial eta-expansion (#7333)
This improves inference of function parameter types for partially eta-expanded methods (i.e., when only some arguments are omitted using
_
)Example from the test, given
def repeat(x: Int, y: String) = y * x
, partial eta-expansion recovers fun param types from the definition of the selected method: