@@ -116,24 +116,37 @@ object CCState:
116
116
*/
117
117
def currentLevel (using Context ): Level = ccState.curLevel
118
118
119
+ /** Perform `op` in the next inner level
120
+ * @pre We are currently in capture checking or setup
121
+ */
119
122
inline def inNestedLevel [T ](inline op : T )(using Context ): T =
120
123
val ccs = ccState
121
124
val saved = ccs.curLevel
122
125
ccs.curLevel = ccs.curLevel.nextInner
123
126
try op finally ccs.curLevel = saved
124
127
128
+ /** Perform `op` in the next inner level unless `p` holds.
129
+ * @pre We are currently in capture checking or setup
130
+ */
125
131
inline def inNestedLevelUnless [T ](inline p : Boolean )(inline op : T )(using Context ): T =
126
132
val ccs = ccState
127
133
val saved = ccs.curLevel
128
134
if ! p then ccs.curLevel = ccs.curLevel.nextInner
129
135
try op finally ccs.curLevel = saved
130
136
137
+ /** If we are currently in capture checking or setup, perform `op` assuming
138
+ * a fresh enclosing binder `mt`, otherwise perform `op` directly.
139
+ */
131
140
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 */
137
150
def openedFreshBinders (using Context ): List [MethodType ] = ccState.openedFreshBinders
138
151
139
152
extension (x : Level )
@@ -147,7 +160,7 @@ object CCState:
147
160
end CCState
148
161
149
162
/** The currently valid CCState */
150
- def ccState (using Context ) =
163
+ def ccState (using Context ): CCState =
151
164
Phases .checkCapturesPhase.asInstanceOf [CheckCaptures ].ccState1
152
165
153
166
extension (tree : Tree )
0 commit comments