Skip to content

Cannot call overloaded method variant with context function parameter #16506

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
prolativ opened this issue Dec 12, 2022 · 0 comments · Fixed by #16511
Closed

Cannot call overloaded method variant with context function parameter #16506

prolativ opened this issue Dec 12, 2022 · 0 comments · Fixed by #16511

Comments

@prolativ
Copy link
Contributor

Compiler version

3.2.1

Minimized code

import scala.annotation.targetName

trait Ctx

def foo(f: Ctx => Int) = ???

@targetName("fooContextual")
def foo(f: Ctx ?=> Int) = ???

def bar1 = foo(ctx => 123)
def bar2 = foo((ctx: Ctx) => 123)
def bar3 = foo(ctx ?=> 123)
def bar4 = foo((ctx: Ctx) ?=> 123)
def bar5 = foo(123)

Output

[error] Tmp.scala:14:16: Found:    (Ctx) ?=> Int
[error] Required: Ctx => Int
[error] def bar3 = foo(ctx ?=> 123)
[error]                ^^^^^^^^^^^
[error] Tmp.scala:15:16: Found:    (Ctx) ?=> Int
[error] Required: Ctx => <?>
[error] def bar4 = foo((ctx: Ctx) ?=> 123)
[error]                ^^^^^^^^^^^^^^^^^^
[error] Tmp.scala:16:16: Found:    (123 : Int)
[error] Required: Ctx => <?>
[error] def bar5 = foo(123)
[error]                ^^^

Expectation

This should compile as the compiler has enough information to know which overloaded method variant to use.

@prolativ prolativ added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label area:overloading and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 12, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue Dec 13, 2022
Fixes scala#16506

We now handle the cases where an argument of an overloaded method is
a context closure. The closure must be given implicitly. It cannot be
inferred since at the time where the argument is typed, there is no expected
expected type to expand it to a context closure.
odersky added a commit to dotty-staging/dotty that referenced this issue Dec 13, 2022
Fixes scala#16506

We now handle the cases where an argument of an overloaded method is
a context closure. The closure must be given implicitly. It cannot be
inferred since at the time where the argument is typed, there is no expected
expected type to expand it to a context closure.
odersky added a commit to dotty-staging/dotty that referenced this issue Dec 13, 2022
Fixes scala#16506

We now handle the cases where an argument of an overloaded method is
a context closure. The closure must be given implicitly. It cannot be
inferred since at the time where the argument is typed, there is no expected
expected type to expand it to a context closure.
odersky added a commit to dotty-staging/dotty that referenced this issue Dec 13, 2022
Fixes scala#16506

We now handle the cases where an argument of an overloaded method is
a context closure. The closure must be given implicitly. It cannot be
inferred since at the time where the argument is typed, there is no expected
expected type to expand it to a context closure.
odersky added a commit that referenced this issue Dec 15, 2022
Fixes #16506

We now handle the cases where an argument of an overloaded method is a
context closure. The closure must be given implicitly. It cannot be
inferred since at the time where the argument is typed, there is no
expected expected type to expand it to a context closure.
little-inferno pushed a commit to little-inferno/dotty that referenced this issue Jan 25, 2023
Fixes scala#16506

We now handle the cases where an argument of an overloaded method is
a context closure. The closure must be given implicitly. It cannot be
inferred since at the time where the argument is typed, there is no expected
expected type to expand it to a context closure.
@Kordyjan Kordyjan added this to the 3.3.0 milestone Aug 1, 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.

2 participants