Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Overload resolution for extension methods fails in some cases where named parameters are involved. #15287

Closed
rmgk opened this issue May 24, 2022 · 6 comments · Fixed by #16009

Comments

@rmgk
Copy link

rmgk commented May 24, 2022

Compiler version

3.1.3-RC3, 3.2.0-RC1-bin-20220519-ee9cc8f-NIGHTLY-git-ee9cc8f

Minimized code

extension (x: Char)
  def f(someParam: String): String = "a"
  def f(min: Boolean, max: Int = 4): String = "b"

@main def run() = 'c'.f(false)

Output

Test.scala:7:19: value f is not a member of Char.
An extension method was tried, but could not be fully constructed:

    extensionOverload.f()    failed with

        value f: <overloaded extensionOverload.f> does not take parameters [7:19]

Expectation

Compile just fine, return "b"

@rmgk rmgk added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 24, 2022
@pikinier20
Copy link
Contributor

Invoking f as a standard method:

f('c')(false)

fails with:

[error] ./cli.scala:5:19: None of the overloaded alternatives of method f with types
[error]  (x: Char)(min: Boolean, max: Int): String
[error]  (x: Char)(someParam: String): String
[error] match arguments (('c' : Char))
[error] @main def run() = f('c')(false)

After specyfing default parameter explicitely, everything compiles

@szymon-rd szymon-rd added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 25, 2022
@pikinier20
Copy link
Contributor

This problem occurs also for standard methods:

def f(x: Char)(someParam: String): String = "a"
def f(x: Char)(min: Boolean, max: Int = 4): String = "b"

@main def run() = f('c')(false)

@pikinier20
Copy link
Contributor

The problem is that compiler expects the default getter name: f$default$2 when actually it is: f$default$3

@pikinier20
Copy link
Contributor

I give up on this as it turned out to be too complicated case. Resolving overloaded methods for curried methods goes param clause per param clause and it's not aware how it should work with default parameters for further parameter clauses.

@odersky
Copy link
Contributor

odersky commented May 29, 2022

One way to fix this for now is to reject overloaded extension methods that have default arguments.

@odersky
Copy link
Contributor

odersky commented Jun 13, 2022

I have decided not to attack errors involving default parameters using the old scheme of default parameters any more. It's better to focus on fixing the scheme to use inline which would fix lots of other problems as well. If people want fixes now, someone else should take this on, or we move to backlog.

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

Successfully merging a pull request may close this issue.

5 participants