Skip to content

Commit e7507a3

Browse files
committed
Refactor with CompareResult#andAlso
1 parent b132fbe commit e7507a3

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,9 @@ object CaptureSet:
269269
if !isConst && recordElemsState() then
270270
elems ++= newElems
271271
// assert(id != 2 || elems.size != 2, this)
272-
val depsIt = deps.iterator
273-
while depsIt.hasNext do
274-
val result = depsIt.next.tryInclude(newElems, this)
275-
if !result.isOK then return result
276-
CompareResult.OK
272+
(CompareResult.OK /: deps) { (r, dep) =>
273+
r.andAlso(dep.tryInclude(newElems, this))
274+
}
277275
else
278276
CompareResult.fail(this)
279277

@@ -359,12 +357,12 @@ object CaptureSet:
359357
report.warning(i"trying to add elems $newElems from unrecognized source $origin of mapped set $this$whereCreated")
360358
return CompareResult.fail(this)
361359
Const(newElems)
362-
val result = super.addNewElems(added.elems, origin)
363-
if result.isOK then
364-
if added.isConst then result
365-
else if added.asVar.recordDepsState() then { addSub(added); result }
366-
else CompareResult.fail(this)
367-
else result
360+
super.addNewElems(added.elems, origin)
361+
.andAlso {
362+
if added.isConst then CompareResult.OK
363+
else if added.asVar.recordDepsState() then { addSub(added); CompareResult.OK }
364+
else CompareResult.fail(this)
365+
}
368366

369367
override def computeApprox(origin: CaptureSet)(using Context): CaptureSet =
370368
if source eq origin then universal
@@ -384,11 +382,11 @@ object CaptureSet:
384382
if origin eq source then
385383
super.addNewElems(newElems.map(bimap.forward), origin)
386384
else
387-
val r = super.addNewElems(newElems, origin)
388-
if r.isOK then
389-
source.tryInclude(newElems.map(bimap.backward), this)
390-
.showing(i"propagating new elems $newElems backward from $this to $source", capt)
391-
else r
385+
super.addNewElems(newElems, origin)
386+
.andAlso {
387+
source.tryInclude(newElems.map(bimap.backward), this)
388+
.showing(i"propagating new elems $newElems backward from $this to $source", capt)
389+
}
392390

393391
override def computeApprox(origin: CaptureSet)(using Context): CaptureSet =
394392
val supApprox = super.computeApprox(this)
@@ -448,7 +446,7 @@ object CaptureSet:
448446
def isOK: Boolean = result eq OK
449447
def blocking: CaptureSet = result
450448
def show: String = if result.isOK then "OK" else result.toString
451-
inline def andAlso(op: => Type) = if result.isOK then op else result
449+
def andAlso(op: Context ?=> Type)(using Context): Type = if result.isOK then op else result
452450

453451
class VarState:
454452
private val elemsMap: util.EqHashMap[Var, Refs] = new util.EqHashMap

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2407,7 +2407,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
24072407
case tp1: TypeVar if tp1.isInstantiated =>
24082408
tp1.underlying & tp2
24092409
case CapturingType(parent1, refs1, _) =>
2410-
if subCaptures(tp2.captureSet, refs1, frozenConstraint) == CaptureSet.CompareResult.OK then
2410+
if subCaptures(tp2.captureSet, refs1, frozenConstraint).isOK then
24112411
parent1 & tp2
24122412
else
24132413
tp1.derivedCapturingType(parent1 & tp2, refs1)

0 commit comments

Comments
 (0)