Skip to content

Inconsistency with partial application/currying between extension methods and functions #9507

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
Tylerwbrown opened this issue Aug 6, 2020 · 0 comments · Fixed by #10902
Closed

Comments

@Tylerwbrown
Copy link

Tylerwbrown commented Aug 6, 2020

Minimized example

extension (x: Int)
  def add(y: Int): Int = x + y

def newFunction: Int => Int = 4.add

object Main extends App:
  println(newFunction(1))

Output

compiler error:

value add is not a member of Int
An extension method was tried, but could not be fully constructed:
  {
    def $anonfun(y: Int): Int = extension_add(4)(y)
    closure($anonfun)
  }

Expectation

5

Explanation

There are 3 other similar cases in which this works as expected, so the above example seems like the odd one out.

extension (x: Int)
  def add: Int => Int = y => x + y

def newFunction: Int => Int = 4.add
def add: Int => Int = y => 4 + y

def newFunction: Int => Int = add
def add(x: Int): Int = x + 4

def newFunction: Int => Int = add

The first two are similar in that both add functions have a return type of Int => Int.

The interesting bit is that the third one works as expected (converting a function defined with (x: Int): Int into Int => Int, but this same conversion doesn't take place inside the context of an extension.

I don't know how extensions are actually implemented, and this might be expected behavior, which is why I didn't categorize this as a bug, just figured I'd mention since it seemed odd to me.

@Tylerwbrown Tylerwbrown changed the title Inconsistency between extension methods and normal methods Inconsistency with partial application/currying between extension methods and functions Aug 6, 2020
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants