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

Singleton type of context function #16488

Closed
prolativ opened this issue Dec 9, 2022 · 5 comments · Fixed by #16490
Closed

Singleton type of context function #16488

prolativ opened this issue Dec 9, 2022 · 5 comments · Fixed by #16490
Assignees
Milestone

Comments

@prolativ
Copy link
Contributor

prolativ commented Dec 9, 2022

Compiler version

3.2.1

Minimized code

trait Ctx
val f: Ctx ?=> Int = ???
def g: f.type = f

Output

-- [E172] Type Error: ----------------------------------------------------------
3 |def g: f.type = f
  |        ^
  |    No given instance of type Ctx was found for parameter of (Ctx) ?=> Int
-- [E172] Type Error: ----------------------------------------------------------
3 |def g: f.type = f
  |                 ^
  |    No given instance of type Ctx was found for parameter of (Ctx) ?=> Int

Expectation

This should compile as it does for non-singleton context function types, e.g.

trait Ctx
val f: Ctx ?=> Int = ???
def g: Ctx ?=> Int = f

and singleton non-contextual function types, e.g.

trait Ctx
val f: Ctx => Int = ???
def g: f.type = f
@prolativ prolativ added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 9, 2022
@odersky
Copy link
Contributor

odersky commented Dec 9, 2022

I think that's out of scope. We need an explicit Ctx context parameter.

@prolativ
Copy link
Contributor Author

prolativ commented Dec 9, 2022

Then should at least this work?

trait Ctx
val f: Ctx ?=> Int = ???
def g: f.type = (ctx: Ctx) ?=> f

Because it doesn't. Although it raises one compiler error less

@odersky
Copy link
Contributor

odersky commented Dec 9, 2022

No that should not work either. You create a new closure, which is different from f.

@prolativ
Copy link
Contributor Author

prolativ commented Dec 9, 2022

Is there any way to refer to the exact type of a given context function then?
It seems quite strange to me that a context function tries to get applied even if we refer to it only in the context of types

trait Ctx
val f: Ctx ?=> Int = ???
type Tpe = f.type
-- Error:
3 |type Tpe = f.type
  |            ^
  | no implicit argument of type Ctx was found for parameter of (Ctx) ?=> Int
trait Ctx
val f: Ctx ?=> Int = ???
given Ctx with {}
type Tpe = f.type
-- Error:
4 |type Tpe = f.type
  |           ^^^^^^
  |      Int is not a valid singleton type, since it is not an immutable path

@odersky
Copy link
Contributor

odersky commented Dec 9, 2022

It seems quite strange to me that a context function tries to get applied even if we refer to it only in the context of types

Yes, that's a bug. Should be easy to fix.

@odersky odersky self-assigned this Dec 9, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue Dec 9, 2022
In a singleton type `f.type`, if `f` is a context function value, don't
complete with implicit arguments.

Fixes scala#16488
@odersky odersky added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 9, 2022
odersky added a commit that referenced this issue Dec 12, 2022
In a singleton type `f.type`, if `f` is a context function value, don't
complete with implicit arguments.

Fixes #16488
little-inferno pushed a commit to little-inferno/dotty that referenced this issue Jan 25, 2023
In a singleton type `f.type`, if `f` is a context function value, don't
complete with implicit arguments.

Fixes scala#16488
@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.

3 participants