Skip to content

No eta-expansion of nilary method when SAM type is expected #9135

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
lrytz opened this issue Jun 9, 2020 · 2 comments
Closed

No eta-expansion of nilary method when SAM type is expected #9135

lrytz opened this issue Jun 9, 2020 · 2 comments

Comments

@lrytz
Copy link
Member

lrytz commented Jun 9, 2020

The folowing doesn't compile, @odersky is this by design?

@FunctionalInterface trait Sam { def f(): Int }
object T {
  def f(): Int = ???
  val x: Sam = f
}

The error is:

4 |  val x: Sam = f
  |               ^
  |               method f must be called with () argument

https://dotty.epfl.ch/docs/reference/changed-features/eta-expansion-spec.html doesn't mention SAM types, it just says

an unapplied method with an empty argument list is only converted to a function when a function type is expected

@odersky
Copy link
Contributor

odersky commented Jun 9, 2020

Yes, that's by design. The clause you cite rules out SAM types. I believe converting unapplied functions to SAM types is dicey anyway, in the sense that it can easily give something unexpected. I personally would have preferred to only convert lambdas to SAMs, not method handles. That ship has sailed, but I am against introducing even more flexibility here.

@odersky odersky closed this as completed Jun 9, 2020
@lrytz
Copy link
Member Author

lrytz commented Jun 9, 2020

OK, so we have to adjust what scalac does under -Xsource:3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants