Skip to content

Commit 8c583b8

Browse files
committed
Address review comments
1 parent 8a1d0ab commit 8c583b8

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

Diff for: compiler/src/dotty/tools/dotc/cc/CaptureOps.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,9 @@ extension (tp: Type)
269269
tp
270270

271271
/** The first element of this path type */
272-
final def pathRoot(using Context): Type = tp.dealiasKeepAnnots match
272+
final def pathRoot(using Context): Type = tp.dealias match
273273
case tp1: NamedType if tp1.symbol.owner.isClass => tp1.prefix.pathRoot
274-
case ReachCapability(tp1) => tp1.pathRoot
275-
case _ => tp
274+
case tp1 => tp1
276275

277276
/** If this part starts with `C.this`, the class `C`.
278277
* Otherwise, if it starts with a reference `r`, `r`'s owner.

Diff for: compiler/src/dotty/tools/dotc/cc/CaptureSet.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ object CaptureSet:
11371137
seen += t.symbol
11381138
val upper = t.info.bounds.hi
11391139
if includeTypevars && upper.isExactlyAny then CaptureSet.universal
1140-
else this(cs, t.info.bounds.hi)
1140+
else this(cs, upper)
11411141
case t @ FunctionOrMethod(args, res @ Existential(_, _))
11421142
if args.forall(_.isAlwaysPure) =>
11431143
this(cs, Existential.toCap(res))

Diff for: compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

+7-9
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,12 @@ class CheckCaptures extends Recheck, SymTransformer:
380380
// A captured reference with the symbol `sym` is visible from the environment
381381
// if `sym` is not defined inside the owner of the environment.
382382
inline def isVisibleFromEnv(sym: Symbol, env: Env) =
383-
if env.kind == EnvKind.NestedInOwner then
384-
!sym.isProperlyContainedIn(env.owner)
385-
else
386-
!sym.isContainedIn(env.owner)
383+
sym.exists && {
384+
if env.kind == EnvKind.NestedInOwner then
385+
!sym.isProperlyContainedIn(env.owner)
386+
else
387+
!sym.isContainedIn(env.owner)
388+
}
387389

388390
/** If captureRef `c` refers to a parameter that is not @use declared, report an error.
389391
* Exception under deferredReaches: If use comes from a nested closure, accept it.
@@ -450,11 +452,7 @@ class CheckCaptures extends Recheck, SymTransformer:
450452
// Only captured references that are visible from the environment
451453
// should be included.
452454
val included = cs.filter: c =>
453-
val isVisible = c.pathRoot match
454-
case ref: NamedType => isVisibleFromEnv(ref.symbol.owner, env)
455-
case ref: ThisType => isVisibleFromEnv(ref.cls, env)
456-
case ref => false
457-
455+
val isVisible = isVisibleFromEnv(c.pathOwner, env)
458456
if !isVisible then
459457
if ccConfig.deferredReaches
460458
then avoidLocalCapability(c, env, lastEnv)

Diff for: compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import config.SourceVersion.*
3030

3131
import dotty.tools.dotc.util.SourcePosition
3232
import dotty.tools.dotc.ast.untpd.{MemberDef, Modifiers, PackageDef, RefTree, Template, TypeDef, ValOrDefDef}
33-
import cc.{CaptureSet, CapturingType, toCaptureSet, IllegalCaptureRef, isRetains, ReachCapability, MaybeCapability, Existential}
33+
import cc.*
3434
import dotty.tools.dotc.parsing.JavaParsers
3535

3636
class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {

Diff for: tests/neg-custom-args/captures/bad-uses-2.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ class Test:
33
@use def F = ??? // error
44
@use val x = ??? // error
55
@use type T // error
6-
def foo(@use c: Test): Unit = ??? // OK
6+
def foo[@use T](@use c: T): Unit = ??? // OK
7+

0 commit comments

Comments
 (0)