Skip to content
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

Handle context function arguments in overloading resolution #16511

Merged
merged 1 commit into from
Dec 15, 2022

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Dec 13, 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.

@odersky odersky force-pushed the fix-16506 branch 2 times, most recently from 069ac2c to a945757 Compare December 13, 2022 16:21
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.
def bar2 = foo((ctx: Ctx) => 123)
def bar3 = foo(ctx ?=> 123)
def bar4 = foo((ctx: Ctx) ?=> 123)
// def bar5 = foo(123) does not work
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about

def f1: Ctx => Int = ???
def f2: Ctx ?=> Int = ???

def bar6 = foo(f1)
def bar7 = foo(f2)

?
Unfortunately bar7 doesn't compile:

19 |def bar7 = foo(f2)
   |               ^^
   |               Found:    (Ctx) ?=> Int
   |               Required: Ctx => <?>

Isn't this a separate case from bar5 as f2 is already known to be a context function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, no. If we expanded bar7 it would look like this:

foo(ctx ?=> f2(using ctx)

So when we see f2 we immediately apply it to a Context argument which is missing, so compilation fails. That's baked in, and I think it will be impossible to change. We exploit this uniformity in our compilation scheme for context functions to make them more efficient.

@prolativ prolativ assigned odersky and unassigned prolativ Dec 14, 2022
@odersky odersky assigned prolativ and unassigned odersky Dec 14, 2022
@odersky odersky merged commit ca5a264 into scala:main Dec 15, 2022
@odersky odersky deleted the fix-16506 branch December 15, 2022 12:55
@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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot call overloaded method variant with context function parameter
3 participants