Skip to content

Commit a585961

Browse files
committed
Interpolate only variables at negative polarity
Interpolating covariant variables risks restricting capture sets to early. For instance, when a variable has the capture set of a called function in its capture set. When we have indirectly recursive calls it could be that the capture set of a called function is not yet fully formed.
1 parent b31a247 commit a585961

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureSet.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ object CaptureSet:
294294
}
295295

296296
def solve(variance: Int)(using Context): Unit =
297-
if variance > 0 then isSolved = true
298-
else if variance < 0 then
297+
if variance < 0 then
299298
val approx = upperApprox
300299
if approx.isConst then
301300
elems = approx.elems
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/boxmap.scala:14:2 ----------------------------------------
22
14 | () => b[Box[B]]((x: A) => box(f(x))) // error
33
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4-
| Found: {f} () => Box[B]
4+
| Found: {f} () => ? Box[B]
55
| Required: () => Box[B]
66

77
longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/capt1.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/capt1.scala:3:2 ------------------------------------------
22
3 | () => if x == null then y else y // error
33
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4-
| Found: {x} () => C
4+
| Found: {x} () => ? C
55
| Required: () => C
66

77
longer explanation available when compiling with `-explain`
88
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/capt1.scala:6:2 ------------------------------------------
99
6 | () => if x == null then y else y // error
1010
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11-
| Found: {x} () => C
11+
| Found: {x} () => ? C
1212
| Required: Matchable
1313

1414
longer explanation available when compiling with `-explain`
@@ -40,7 +40,7 @@ longer explanation available when compiling with `-explain`
4040
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/capt1.scala:31:24 ----------------------------------------
4141
31 | val z2 = h[() => Cap](() => x)(() => C()) // error
4242
| ^^^^^^^
43-
| Found: {x} () => Cap
43+
| Found: {x} () => ? Cap
4444
| Required: () => Cap
4545

4646
longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/try.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/try.scala:28:43 ------------------------------------------
22
28 | val b = handle[Exception, () => Nothing] { // error
33
| ^
4-
| Found: ? (x: CanThrow[Exception]) => {x} () => Nothing
4+
| Found: ? (x: CanThrow[Exception]) => {x} () => ? Nothing
55
| Required: CanThrow[Exception] => () => Nothing
66
29 | (x: CanThrow[Exception]) => () => raise(new Exception)(using x)
77
30 | } {

0 commit comments

Comments
 (0)