Skip to content

Commit 74696b9

Browse files
committed
Improve error message for escaping capabilities
1 parent 7c642c2 commit 74696b9

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,9 @@ extends tpd.TreeTraverser:
303303
val polyType = fn.tpe.widen.asInstanceOf[TypeLambda]
304304
for case (arg: TypeTree, pinfo, pname) <- args.lazyZip(polyType.paramInfos).lazyZip((polyType.paramNames)) do
305305
if pinfo.bounds.hi.hasAnnotation(defn.Caps_SealedAnnot) then
306-
def where = if fn.symbol.exists then i" in the body of ${fn.symbol}" else ""
306+
def where = if fn.symbol.exists then i" in an argument of ${fn.symbol}" else ""
307307
CheckCaptures.disallowRootCapabilitiesIn(arg.knownType,
308-
i"Sealed type variable $pname", " be instantiated to",
308+
i"Sealed type variable $pname", "be instantiated to",
309309
i"This is often caused by a local capability$where\nleaking as part of its result.",
310310
tree.srcPos)
311311
case _ =>
@@ -346,7 +346,7 @@ extends tpd.TreeTraverser:
346346
if prevLambdas.isEmpty then restp
347347
else SubstParams(prevPsymss, prevLambdas)(restp)
348348

349-
if tree.tpt.hasRememberedType && !sym.isConstructor then
349+
if sym.exists && tree.tpt.hasRememberedType && !sym.isConstructor then
350350
val newInfo = integrateRT(sym.info, sym.paramSymss, Nil, Nil)
351351
.showing(i"update info $sym: ${sym.info} --> $result", capt)
352352
if newInfo ne sym.info then

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
-- Error: tests/neg-custom-args/captures/try.scala:23:16 ---------------------------------------------------------------
22
23 | val a = handle[Exception, CanThrow[Exception]] { // error
33
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4-
| Sealed type variable R cannot be instantiated to box CT[Exception]^ since
4+
| Sealed type variable R cannot be instantiated to box CT[Exception]^ since
55
| that type captures the root capability `cap`.
6-
| This is often caused by a local capability in the body of method handle
6+
| This is often caused by a local capability in an argument of method handle
77
| leaking as part of its result.
88
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/try.scala:29:43 ------------------------------------------
99
29 | val b = handle[Exception, () -> Nothing] { // error
@@ -31,7 +31,7 @@
3131
-- Error: tests/neg-custom-args/captures/try.scala:35:11 ---------------------------------------------------------------
3232
35 | val xx = handle { // error
3333
| ^^^^^^
34-
| Sealed type variable R cannot be instantiated to box () => Int since
34+
| Sealed type variable R cannot be instantiated to box () => Int since
3535
| that type captures the root capability `cap`.
36-
| This is often caused by a local capability in the body of method handle
36+
| This is often caused by a local capability in an argument of method handle
3737
| leaking as part of its result.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Error: tests/neg-custom-args/captures/usingLogFile-alt.scala:18:2 ---------------------------------------------------
22
18 | usingFile( // error
33
| ^^^^^^^^^
4-
| Sealed type variable T cannot be instantiated to box () => Unit since
4+
| Sealed type variable T cannot be instantiated to box () => Unit since
55
| that type captures the root capability `cap`.
6-
| This is often caused by a local capability in the body of method usingFile
6+
| This is often caused by a local capability in an argument of method usingFile
77
| leaking as part of its result.

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
-- Error: tests/neg-custom-args/captures/usingLogFile.scala:23:14 ------------------------------------------------------
1414
23 | val later = usingLogFile { f => () => f.write(0) } // error
1515
| ^^^^^^^^^^^^
16-
| Sealed type variable T cannot be instantiated to box () => Unit since
16+
| Sealed type variable T cannot be instantiated to box () => Unit since
1717
| that type captures the root capability `cap`.
18-
| This is often caused by a local capability in the body of method usingLogFile
18+
| This is often caused by a local capability in an argument of method usingLogFile
1919
| leaking as part of its result.
2020
-- Error: tests/neg-custom-args/captures/usingLogFile.scala:28:23 ------------------------------------------------------
2121
28 | private val later2 = usingLogFile { f => Cell(() => f.write(0)) } // error
2222
| ^^^^^^^^^^^^
23-
| Sealed type variable T cannot be instantiated to box Test2.Cell[() => Unit]^? since
23+
| Sealed type variable T cannot be instantiated to box Test2.Cell[() => Unit]^? since
2424
| the part () => Unit of that type captures the root capability `cap`.
25-
| This is often caused by a local capability in the body of method usingLogFile
25+
| This is often caused by a local capability in an argument of method usingLogFile
2626
| leaking as part of its result.
2727
-- Error: tests/neg-custom-args/captures/usingLogFile.scala:47:6 -------------------------------------------------------
2828
47 | val later = usingLogFile { f => () => f.write(0) } // error
@@ -34,14 +34,14 @@
3434
-- Error: tests/neg-custom-args/captures/usingLogFile.scala:62:16 ------------------------------------------------------
3535
62 | val later = usingFile("out", f => (y: Int) => xs.foreach(x => f.write(x + y))) // error
3636
| ^^^^^^^^^
37-
| Sealed type variable T cannot be instantiated to box (x$0: Int) => Unit since
37+
| Sealed type variable T cannot be instantiated to box (x$0: Int) => Unit since
3838
| that type captures the root capability `cap`.
39-
| This is often caused by a local capability in the body of method usingFile
39+
| This is often caused by a local capability in an argument of method usingFile
4040
| leaking as part of its result.
4141
-- Error: tests/neg-custom-args/captures/usingLogFile.scala:71:16 ------------------------------------------------------
4242
71 | val later = usingFile("logfile", // error
4343
| ^^^^^^^^^
44-
| Sealed type variable T cannot be instantiated to box () => Unit since
44+
| Sealed type variable T cannot be instantiated to box () => Unit since
4545
| that type captures the root capability `cap`.
46-
| This is often caused by a local capability in the body of method usingFile
46+
| This is often caused by a local capability in an argument of method usingFile
4747
| leaking as part of its result.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
-- Error: tests/neg-custom-args/captures/vars.scala:32:2 ---------------------------------------------------------------
2121
32 | local { cap3 => // error
2222
| ^^^^^
23-
| Sealed type variable T cannot be instantiated to box (x$0: String) => String since
23+
| Sealed type variable T cannot be instantiated to box (x$0: String) => String since
2424
| that type captures the root capability `cap`.
25-
| This is often caused by a local capability in the body of method local
25+
| This is often caused by a local capability in an argument of method local
2626
| leaking as part of its result.

0 commit comments

Comments
 (0)