Skip to content

Commit 3374d3a

Browse files
committed
Be more precise for the inCaptureCheckingOrSetup test
1 parent 5758700 commit 3374d3a

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,17 @@ class CCState:
7070

7171
// ------ Iteration count of capture checking run
7272

73-
private var iterCount = 1
73+
private var iterCount = 0
7474

7575
def iterationId = iterCount
7676

7777
def nextIteration[T](op: => T): T =
7878
iterCount += 1
7979
try op finally iterCount -= 1
8080

81+
def start(): Unit =
82+
iterCount = 1
83+
8184
// ------ Global counters -----------------------
8285

8386
/** Next CaptureSet.Var id */

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,18 @@ private val Captures: Key[CaptureSet] = Key()
2222
def isCaptureChecking(using Context): Boolean =
2323
ctx.phaseId == Phases.checkCapturesPhase.id
2424

25-
/** Are we at checkCaptures or Setup phase? */
25+
/** Are we in the CheckCaptures or Setup phase? */
2626
def isCaptureCheckingOrSetup(using Context): Boolean =
27-
val ccId = Phases.checkCapturesPhase.id
28-
val ctxId = ctx.phaseId
29-
ctxId == ccId || ctxId == ccId - 1
27+
val ccPhase = Phases.checkCapturesPhase
28+
ccPhase.exists
29+
&& {
30+
val ccId = ccPhase.id
31+
val ctxId = ctx.phaseId
32+
ctxId == ccId
33+
|| ctxId == ccId - 1 && ccState.iterationId > 0
34+
// Note: just checking phase id is not enough since Setup would
35+
// also be the phase after pattern matcher.
36+
}
3037

3138
/** A dependent function type with given arguments and result type
3239
* TODO Move somewhere else where we treat all function type related ops together.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,7 @@ class CheckCaptures extends Recheck, SymTransformer:
17611761
private val setup: SetupAPI = thisPhase.prev.asInstanceOf[Setup]
17621762

17631763
override def checkUnit(unit: CompilationUnit)(using Context): Unit =
1764+
ccState.start()
17641765
setup.setupUnit(unit.tpdTree, this)
17651766
collectCapturedMutVars.traverse(unit.tpdTree)
17661767

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
10101010
if isCaptureCheckingOrSetup then
10111011
tp1
10121012
.match
1013-
case tp1: Capability if tp1.isTracked =>
1013+
case tp1: Capability if isCaptureCheckingOrSetup && tp1.isTracked =>
10141014
CapturingType(tp1w.stripCapturing, tp1.singletonCaptureSet)
10151015
case _ =>
10161016
tp1w
@@ -2110,7 +2110,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
21102110
* since `T >: Int` is subsumed by both alternatives in the first match clause.
21112111
*
21122112
* However, the following should not:
2113-
*
2113+
*
21142114
* def foo[T](e: Expr[T]): T = e match
21152115
* case I1(_) | B(_) => 42
21162116
*

0 commit comments

Comments
 (0)