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

Error message with capture sets variables can be confusing #21998

Open
odersky opened this issue Nov 21, 2024 · 0 comments
Open

Error message with capture sets variables can be confusing #21998

odersky opened this issue Nov 21, 2024 · 0 comments
Labels
area:experimental:cc Capture checking related area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement

Comments

@odersky
Copy link
Contributor

odersky commented Nov 21, 2024

Compiler version

3.6.2

Minimized example

import language.experimental.captureChecking

class Cap extends caps.Capability

def test(cap1: Cap, cap2: Cap) =
  def f2(): Int ->{cap1} Int = ???
  def h(ff: () -> Int ->{cap2} Int) = ???
  h(() => f2())  // error

Output

-- [E007] Type Mismatch Error: ../../new/test.scala:8:12 -----------------------
8 |  h(() => f2())  // error
  |          ^^^^
  |          Found:    Int ->{cap1} Int
  |          Required: (x$0: Int) ->? Int

Expectation

I would have liked to see instead:

  |          Required: (x$0: Int) ->{cap2} Int

The problem is that there a capture set variable generated for the closure result which has {cap2} as its upper capture set. That information is important, but gets suppressed in the error diagnostic. We could take all contravariant capture sets in the expected type and interpolate each of them with the maximal set that satisfies their constraints. Then, if the subtype test still fails we could use the interpolated sets instead of the original variables. That would help.

@odersky odersky added the stat:needs triage Every issue needs to have an "area" and "itype" label label Nov 21, 2024
@Gedochao Gedochao added itype:enhancement area:experimental:cc Capture checking related better-errors Issues concerned with improving confusing/unhelpful diagnostic messages area:reporting Error reporting including formatting, implicit suggestions, etc and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 22, 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 area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement
Projects
None yet
Development

No branches or pull requests

2 participants