Skip to content

Commit fd243f7

Browse files
committed
Cleanups
1 parent 09e4e0f commit fd243f7

File tree

3 files changed

+22
-33
lines changed

3 files changed

+22
-33
lines changed

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ class CheckCaptures extends Recheck, SymTransformer:
277277
traverseChildren(tp)
278278

279279
checker.traverse(tpe)
280-
//println(i"check $tpe = ${checker.seenRefs}")
281280
if checker.seenRefs.size == 2
282281
&& checker.seenRefs(true) >= 0
283282
&& checker.seenRefs(false) <= 0
@@ -286,30 +285,8 @@ class CheckCaptures extends Recheck, SymTransformer:
286285
em"""Reach capability ${showRef(checker.seenReach.nn)} and universal capability cap cannot both
287286
|appear in the type $tpe of this expression""",
288287
pos)
289-
290288
end checkReachCapsIsolated
291289

292-
// Uses 4-space indent as a trial
293-
def checkReachCapsOnlyCovariant(tpe: Type, pos: SrcPos)(using Context): Unit =
294-
val checker = new TypeTraverser:
295-
def traverse(tp: Type) =
296-
tp match
297-
case CapturingType(parent, refs) =>
298-
traverse(parent)
299-
if variance <= 0 then
300-
for ref <- refs.elems do
301-
if ref.isReach then
302-
val prefix = if variance == 0 then "in" else "contra"
303-
report.error(
304-
em"""Reach capability ${showRef(ref)} is not allowed to appear in ${prefix}variant position
305-
|in argument type $tpe""",
306-
pos
307-
)
308-
case _ =>
309-
traverseChildren(tp)
310-
checker.traverse(tpe)
311-
end checkReachCapsOnlyCovariant
312-
313290
/** The current environment */
314291
private val rootEnv: Env = inContext(ictx):
315292
Env(defn.RootClass, EnvKind.Regular, CaptureSet.empty, null)
@@ -514,12 +491,6 @@ class CheckCaptures extends Recheck, SymTransformer:
514491
case appType => appType
515492
end recheckApply
516493

517-
// Uses 4-space indent as a trial
518-
override def recheckArg(arg: Tree, pt: Type)(using Context) =
519-
val argType = recheck(arg, pt)
520-
//checkReachCapsOnlyCovariant(argType.widen, arg.srcPos)
521-
argType
522-
523494
private def isDistinct(xs: List[Type]): Boolean = xs match
524495
case x :: xs1 => xs1.isEmpty || !xs1.contains(x) && isDistinct(xs1)
525496
case Nil => true

compiler/src/dotty/tools/dotc/transform/Recheck.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ abstract class Recheck extends Phase, SymTransformer:
311311
else fntpe.paramInfos
312312
def recheckArgs(args: List[Tree], formals: List[Type], prefs: List[ParamRef]): List[Type] = args match
313313
case arg :: args1 =>
314-
val argType = recheckArg(arg, normalizeByName(formals.head))
314+
val argType = recheck(arg, normalizeByName(formals.head))
315315
val formals1 =
316316
if fntpe.isParamDependent
317317
then formals.tail.map(_.substParam(prefs.head, argType))
@@ -326,9 +326,6 @@ abstract class Recheck extends Phase, SymTransformer:
326326
case tp =>
327327
assert(false, i"unexpected type of ${tree.fun}: $tp")
328328

329-
def recheckArg(arg: Tree, pt: Type)(using Context): Type =
330-
recheck(arg, normalizeByName(pt))
331-
332329
def recheckTypeApply(tree: TypeApply, pt: Type)(using Context): Type =
333330
val funtpe = recheck(tree.fun)
334331
tree.fun.rememberType(funtpe) // remember type to support later bounds checks

tests/neg/unsound-reach-3.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import language.experimental.captureChecking
2+
trait File:
3+
def close(): Unit
4+
5+
def withFile[R](path: String)(op: File^ => R): R = ???
6+
7+
trait Foo[+X]:
8+
def use(x: File^): X
9+
class Bar extends Foo[File^]:
10+
def use(x: File^): File^ = x
11+
12+
def bad(): Unit =
13+
val backdoor: Foo[File^] = new Bar
14+
val boom: Foo[File^{backdoor*}] = backdoor
15+
16+
var escaped: File^{backdoor*} = null
17+
withFile("hello.txt"): f =>
18+
escaped = boom.use(f) // error
19+
// boom.use: (x: File^) -> File^{backdoor*}, it is a selection so reach capabilities are allowed
20+
// f: File^, so there is no reach capabilities
21+

0 commit comments

Comments
 (0)