Skip to content

Commit 77f60a1

Browse files
committed
Make formalCaptures use the spanCaptureSet
1 parent bc93c9e commit 77f60a1

File tree

3 files changed

+5
-20
lines changed

3 files changed

+5
-20
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
341341
* the latter contains a cap.
342342
*/
343343
private def formalCaptures(arg: Tree)(using Context): Refs =
344-
arg.formalType.orElse(arg.nuType).deepCaptureSet.elems
344+
arg.formalType.orElse(arg.nuType).spanCaptureSet.elems
345345

346346
/** The span capture set if the type of `tree` */
347347
private def spanCaptures(tree: Tree)(using Context): Refs =
@@ -402,7 +402,7 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
402402
if clashIdx == 0 && !isShowableMethod then "" // we already mentioned the type in `funStr`
403403
else i" with type ${clashing.nuType}"
404404
val hiddenSet = formalCaptures(polyArg).transHiddenSet
405-
val clashSet = deepCaptures(clashing)
405+
val clashSet = if clashIdx == -1 then deepCaptures(clashing) else spanCaptures(clashing)
406406
val hiddenFootprint = hiddenSet.directFootprint
407407
val clashFootprint = clashSet.directFootprint
408408
report.error(
@@ -891,10 +891,11 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
891891
val resultType = mtpe.finalResultType
892892
val resultCaptures =
893893
(resultArgCaptures(resultType) ++ resultType.deepCaptureSet.elems).filter(!isLocalRef(_))
894+
// See i23726.scala why deepCaptureSet is needed here.
894895
val resultPeaks = resultCaptures.allPeaks
895896
capt.println(i"deps for $app = ${deps.toList}")
896897
(deps, resultPeaks)
897-
898+
end dependencies
898899

899900
/** Decompose an application into a function prefix and a list of argument lists.
900901
* If some of the arguments need a separation check because they are capture polymorphic,

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
-- Error: tests/neg-custom-args/captures/sepchecks2.scala:13:7 ---------------------------------------------------------
2-
13 | foo((() => println(c)) :: Nil, c) // error
3-
| ^^^^^^^^^^^^^^^^^^^^^^^^
4-
|Separation failure: argument of type List[() ->{c} Unit]
5-
|to method foo: (xs: List[() => Unit], y: Object^): Nothing
6-
|corresponds to capture-polymorphic formal parameter xs of type List[() => Unit]
7-
|and hides capabilities {c}.
8-
|Some of these overlap with the captures of the second argument with type (c : Object^).
9-
|
10-
| Hidden set of current argument : {c}
11-
| Hidden footprint of current argument : {c}
12-
| Capture set of second argument : {c}
13-
| Footprint set of second argument : {c}
14-
| The two sets overlap at : {c}
15-
|
16-
|where: => refers to a fresh root capability created in method Test2 when checking argument to parameter xs of method foo
171
-- Error: tests/neg-custom-args/captures/sepchecks2.scala:14:10 --------------------------------------------------------
182
14 | val x1: (Object^, Object^) = (c, c) // error
193
| ^^^^^^^^^^^^^^^^^^

tests/neg-custom-args/captures/sepchecks2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def Test(consume c: Object^) =
1010
println(c)
1111

1212
def Test2(c: Object^, d: Object^): Unit =
13-
foo((() => println(c)) :: Nil, c) // error
13+
foo((() => println(c)) :: Nil, c) // ok
1414
val x1: (Object^, Object^) = (c, c) // error
1515
val x2: (Object^, Object^{d}) = (d, d) // error
1616

0 commit comments

Comments
 (0)