Open
Description
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.