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

Function parameter types not inferred in the presence of default arguments #11322

Open
lihaoyi opened this issue Dec 19, 2018 · 4 comments
Open
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) infer typer
Milestone

Comments

@lihaoyi
Copy link

lihaoyi commented Dec 19, 2018

@ def foo(i: Int, j: Int) = i
defined function foo

@ foo(_, 1)
res5: Int => Int = ammonite.$sess.cmd5$$$Lambda$1703/0x0000000800a05040@396e6d9

@ def bar(i: Int, j: Int, k: Int = 2) = i
defined function bar

@ bar(_, 1)
cmd7.sc:1: missing parameter type for expanded function ((x$1: <error>) => bar(x$1, 1))
val res7 = bar(_, 1)
               ^
Compilation Failed

Seems like scala/scala#7340 missed a case; I would expect eta expansion to work for both

@SethTisue
Copy link
Member

@adriaanm shall we milestone this for RC1, or not?

@adriaanm
Copy link
Contributor

I don’t think I’ll be able to add support for named/defaults by the RC. let’s schedule for 2.13.1

@adriaanm adriaanm self-assigned this Jan 16, 2019
@adriaanm adriaanm added this to the 2.13.1 milestone Jan 16, 2019
@szeiger szeiger modified the milestones: 2.13.1, 2.13.2 Aug 28, 2019
@SethTisue SethTisue modified the milestones: 2.13.2, 2.13.3 Feb 6, 2020
@SethTisue SethTisue modified the milestones: 2.13.3, 2.13.4 May 12, 2020
@dwijnand dwijnand modified the milestones: 2.13.4, Backlog Oct 20, 2020
@SethTisue SethTisue added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Oct 20, 2020
@dwijnand
Copy link
Member

dwijnand commented Oct 20, 2020

There's already the issue that you can't invoke def foo(x: Int = 1) with simply foo:

scala> def foo(x: Int = 1) = x.toString
def foo(x: Int): String

scala> foo
       ^
       error: missing argument list for method foo
       Unapplied methods are only converted to functions when a function type is expected.
       You can make this conversion explicit by writing `foo _` or `foo(_)` instead of `foo`.

@SethTisue
Copy link
Member

SethTisue commented Oct 20, 2020

There's already the issue that you can't invoke def foo(x: Int = 1) with simply foo:

that's as expected, I think, since Dotty aims to eliminate any need for foo _ syntax to exist, so just foo by itself eta-expands:

Starting dotty REPL...
scala> def foo(x: Int = 1) = x.toString                                                                                 
def foo(x: Int): String
def foo$default$1: Int

scala> foo                                                                                                              
val res0: Int => String = Lambda$1223/289710123@13ef7fa1

but it's kind of a tangent, since this ticket is about lambdas, not about eta-expansion per se. I will re-title the ticket not to refer to "eta expansion".

@SethTisue SethTisue changed the title Improved eta-expansion doesn't work for methods with default arguments Function parameter types not inferred in the presence of default arguments Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) infer typer
Projects
None yet
Development

No branches or pull requests

5 participants