Skip to content
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

Merged
merged 5 commits into from
Nov 2, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[backport] Recover fun param types from (partial) eta-expansion
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
  • Loading branch information
adriaanm committed Oct 15, 2018
commit 93cd804a78516fb27576b616b5260112c10a0db6
6 changes: 6 additions & 0 deletions test/files/pos/eta_partial.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Test {
def repeat(x: Int, y: String) = y * x
val sayAaah = repeat(_, "a") // partial eta-expansion recovers fun param types from method (place holder syntax)
val thrice = x => repeat(3, x) // partial eta-expansion recovers fun param types from method (explicit version)
val repeatFlip = (x, y) => repeat(y, x) // partial eta-expansion recovers fun param types from method (explicit version, two params)
}