@@ -103,11 +103,12 @@ class TyperState() {
103
103
this
104
104
105
105
/** A fresh typer state with the same constraint as this one. */
106
- def fresh (reporter : Reporter = StoreReporter (this .reporter)): TyperState =
106
+ def fresh (reporter : Reporter = StoreReporter (this .reporter),
107
+ committable : Boolean = this .isCommittable): TyperState =
107
108
util.Stats .record(" TyperState.fresh" )
108
109
TyperState ().init(this , this .constraint)
109
110
.setReporter(reporter)
110
- .setCommittable(this .isCommittable )
111
+ .setCommittable(committable )
111
112
112
113
/** The uninstantiated variables */
113
114
def uninstVars : collection.Seq [TypeVar ] = constraint.uninstVars
@@ -182,24 +183,25 @@ class TyperState() {
182
183
183
184
/** Integrate the constraints from `that` into this TyperState.
184
185
*
185
- * @pre If `that` is committable, it must not contain any type variable which
186
+ * @pre If `this` and ` that` are committable, `that` must not contain any type variable which
186
187
* does not exist in `this` (in other words, all its type variables must
187
188
* be owned by a common parent of `this` and `that`).
188
189
*/
189
- def mergeConstraintWith (that : TyperState )(using Context ): Unit =
190
+ def mergeConstraintWith (that : TyperState )(using Context ): this .type =
191
+ if this eq that then return this
192
+
190
193
that.ensureNotConflicting(constraint)
191
194
192
- val comparingCtx =
193
- if ctx.typerState == this then ctx
194
- else ctx.fresh.setTyperState(this )
195
+ val comparingCtx = ctx.withTyperState(this )
195
196
196
- comparing(typeComparer =>
197
+ inContext(comparingCtx)( comparing(typeComparer =>
197
198
val other = that.constraint
198
199
val res = other.domainLambdas.forall(tl =>
199
200
// Integrate the type lambdas from `other`
200
201
constraint.contains(tl) || other.isRemovable(tl) || {
201
202
val tvars = tl.paramRefs.map(other.typeVarOfParam(_)).collect { case tv : TypeVar => tv }
202
- tvars.foreach(tvar => if ! tvar.inst.exists && ! isOwnedAnywhere(this , tvar) then includeVar(tvar))
203
+ if this .isCommittable then
204
+ tvars.foreach(tvar => if ! tvar.inst.exists && ! isOwnedAnywhere(this , tvar) then includeVar(tvar))
203
205
typeComparer.addToConstraint(tl, tvars)
204
206
}) &&
205
207
// Integrate the additional constraints on type variables from `other`
@@ -220,10 +222,11 @@ class TyperState() {
220
222
)
221
223
)
222
224
assert(res || ctx.reporter.errorsReported, i " cannot merge $constraint with $other. " )
223
- )( using comparingCtx )
225
+ ))
224
226
225
227
for tl <- constraint.domainLambdas do
226
228
if constraint.isRemovable(tl) then constraint = constraint.remove(tl)
229
+ this
227
230
end mergeConstraintWith
228
231
229
232
/** Take ownership of `tvar`.
0 commit comments