Skip to content

Commit 93758e5

Browse files
committed
Make inOpenedFreshBinder work also if there is no capture checking phase
1 parent 8db5a46 commit 93758e5

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,37 @@ object CCState:
116116
*/
117117
def currentLevel(using Context): Level = ccState.curLevel
118118

119+
/** Perform `op` in the next inner level
120+
* @pre We are currently in capture checking or setup
121+
*/
119122
inline def inNestedLevel[T](inline op: T)(using Context): T =
120123
val ccs = ccState
121124
val saved = ccs.curLevel
122125
ccs.curLevel = ccs.curLevel.nextInner
123126
try op finally ccs.curLevel = saved
124127

128+
/** Perform `op` in the next inner level unless `p` holds.
129+
* @pre We are currently in capture checking or setup
130+
*/
125131
inline def inNestedLevelUnless[T](inline p: Boolean)(inline op: T)(using Context): T =
126132
val ccs = ccState
127133
val saved = ccs.curLevel
128134
if !p then ccs.curLevel = ccs.curLevel.nextInner
129135
try op finally ccs.curLevel = saved
130136

137+
/** If we are currently in capture checking or setup, perform `op` assuming
138+
* a fresh enclosing binder `mt`, otherwise perform `op` directly.
139+
*/
131140
inline def inOpenedFreshBinder[T](mt: MethodType)(op: => T)(using Context): T =
132-
val ccs = ccState
133-
val saved = ccs.openedFreshBinders
134-
if mt.isFreshBinder then ccs.openedFreshBinders = mt :: ccs.openedFreshBinders
135-
try op finally ccs.openedFreshBinders = saved
136-
141+
if isCaptureCheckingOrSetup then
142+
val ccs = ccState
143+
val saved = ccs.openedFreshBinders
144+
if mt.isFreshBinder then ccs.openedFreshBinders = mt :: ccs.openedFreshBinders
145+
try op finally ccs.openedFreshBinders = saved
146+
else
147+
op
148+
149+
/** The currently opened fresh binders */
137150
def openedFreshBinders(using Context): List[MethodType] = ccState.openedFreshBinders
138151

139152
extension (x: Level)
@@ -147,7 +160,7 @@ object CCState:
147160
end CCState
148161

149162
/** The currently valid CCState */
150-
def ccState(using Context) =
163+
def ccState(using Context): CCState =
151164
Phases.checkCapturesPhase.asInstanceOf[CheckCaptures].ccState1
152165

153166
extension (tree: Tree)

0 commit comments

Comments
 (0)