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

Function classes fail capture checking #18857

Closed
Linyxus opened this issue Nov 6, 2023 · 2 comments · Fixed by #20004
Closed

Function classes fail capture checking #18857

Linyxus opened this issue Nov 6, 2023 · 2 comments · Fixed by #20004
Assignees
Labels
area:experimental:cc Capture checking related cc-experiment Intended to be merged with cc-experiment branch on origin itype:bug
Milestone

Comments

@Linyxus
Copy link
Contributor

Linyxus commented Nov 6, 2023

Compiler version

main

Minimized code

import language.experimental.captureChecking

val x = new (Int => Unit) {
  def apply(x: Int): Unit = ()
}

Output

-- [E007] Type Mismatch Error: issues/cc-classes.scala:5:1 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5 |}
  | ^
  | Found:    Object with (Int => Unit) {...}^?
  | Required: (x$0: Int) ->? Unit
  |
  | longer explanation available when compiling with `-explain`
1 error found

Expectation

It should compile.

@Linyxus Linyxus added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 6, 2023
@Linyxus Linyxus changed the title Function classes always fail capture checking Function classes fail capture checking Nov 6, 2023
@Kordyjan Kordyjan added cc-experiment Intended to be merged with cc-experiment branch on origin area:experimental:cc Capture checking related and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 7, 2023
@noti0na1 noti0na1 self-assigned this Mar 4, 2024
@noti0na1
Copy link
Member

noti0na1 commented Mar 4, 2024

Extra tests:

class F extends (Int => Unit) {
  def apply(x: Int): Unit = ()
}

val y: Int => Unit = new F
val z: Int -> Unit = new F

@noti0na1
Copy link
Member

noti0na1 commented Mar 4, 2024

Steps:

  1. Consider capture set from underlying/parent types;
  2. Ignore capture set after being compared.

@nicolasstucki nicolasstucki assigned Florian3k and unassigned noti0na1 Mar 19, 2024
@noti0na1 noti0na1 assigned noti0na1 and unassigned Florian3k Mar 19, 2024
odersky added a commit that referenced this issue Apr 27, 2024
Fix #18857
This PR checks universal capability from parent classes properly.
@Kordyjan Kordyjan added this to the 3.5.0 milestone May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:experimental:cc Capture checking related cc-experiment Intended to be merged with cc-experiment branch on origin itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants