Skip to content

Deprecate method value (foo _) syntax? #273

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

Closed
SethTisue opened this issue Nov 23, 2016 · 7 comments
Closed

Deprecate method value (foo _) syntax? #273

SethTisue opened this issue Nov 23, 2016 · 7 comments

Comments

@SethTisue
Copy link
Member

SethTisue commented Nov 23, 2016

the difference between foo _ and foo(_) (or foo(_, _) and so on) has always been a puzzler factory.

if the choice is between foo _ and foo(_), then losing the first option isn't bad, but if the choice is between foo _ and foo(_, _, _, _, _, _) then it starts feeling different.

but in the wild, perhaps most uses of foo _ would also compile simply as foo because a function type is already expected?

personally, I think I tend to write foo _ even when just foo would compile, just to explicitly signal to the reader that foo is definitely not being called.

@sjrd
Copy link
Member

sjrd commented Nov 23, 2016

For 0 argument the only alternative is () => foo(). Especially now that automatic eta-expansion of 0-arg methods is deprecated.

@adriaanm
Copy link
Contributor

adriaanm commented Jun 3, 2017

True, but I think the benefit of

  • eta-expanding more uniformly (except for 0-ary methods, but regardless of the expected type), and
  • removing method value syntax

outweighs having to explicitly eta-expand for the 0-ary case.

@SethTisue
Copy link
Member Author

SethTisue commented Jun 6, 2017

this is being taken up at scala/scala3#2570

foo(_, _, _, _, _, _) will never be necessary because just foo will always work

@Atry
Copy link

Atry commented Feb 27, 2018

@adriaanm Or stop parenthesis injection for nullary functions.

@adriaanm
Copy link
Contributor

adriaanm commented Mar 6, 2018

Dotty's doing that, but I don't think we can make everyone insert the needed () in their code base in 2.13.

@adriaanm adriaanm added this to the 2.13.0-M5 milestone Jun 14, 2018
@adriaanm adriaanm changed the title 2.13: deprecate method value (foo _) syntax? Deprecate method value (foo _) syntax? Jun 14, 2018
@adriaanm
Copy link
Contributor

Carried over from #489:

Currently, http://www.scala-lang.org/files/archive/spec/2.12/06-expressions.html#method-values says:

The expression e _ is well-formed if e is of method type or if e is a call-by-name parameter. [...]
If e is a parameterless method or call-by-name parameter of type => T, e _ represents the function of type () => T, which evaluates e when it is applied to the empty parameter list ().

Since we've removed eta-expansion for nullary methods, for consistency we should also deprecate and drop the last part re: "parameterless method or call-by-name parameter". Those will need to be written explicitly using () => e.

Eventually (ideally), all method references will be eta-expanded regardless of expected type, and method value syntax will be dropped since it's redundant.

@SethTisue SethTisue modified the milestones: 2.13.0-M5, 2.13.0-RC1 Aug 7, 2018
@adriaanm adriaanm modified the milestones: 2.13.0-RC1, 2.13.1 Aug 7, 2018
@szeiger szeiger modified the milestones: 2.13.1, 2.13.2 Sep 9, 2019
@SethTisue SethTisue modified the milestones: 2.13.2, 2.13.3 Feb 6, 2020
@SethTisue
Copy link
Member Author

this is happening in Dotty eventually, but out of scope for Scala 2

@SethTisue SethTisue removed this from the 2.13.3 milestone Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants