Skip to content

Commit 74fcbf1

Browse files
committed
Simplify augmentConstructor
1 parent 8d17dfb commit 74fcbf1

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -414,15 +414,19 @@ class CheckCaptures extends Recheck, SymTransformer:
414414
* Second half: union of all capture sets of arguments to tracked parameters.
415415
*/
416416
def addParamArgRefinements(core: Type, initCs: CaptureSet): (Type, CaptureSet) =
417-
mt.paramNames.lazyZip(argTypes).foldLeft((core, initCs)) { (acc, refine) =>
418-
val (core, allCaptures) = acc
419-
val (getterName, argType) = refine
417+
var refined: Type = core
418+
var allCaptures: CaptureSet = initCs
419+
for (getterName, argType) <- mt.paramNames.lazyZip(argTypes) do
420420
val getter = cls.info.member(getterName).suchThat(_.is(ParamAccessor)).symbol
421-
if getter.termRef.isTracked && !getter.is(Private)
422-
then (RefinedType(core, getterName, argType), allCaptures ++ argType.captureSet)
423-
else (core, allCaptures)
424-
}
425-
421+
if getter.termRef.isTracked && !getter.is(Private) then
422+
refined = RefinedType(refined, getterName, argType)
423+
allCaptures ++= argType.captureSet
424+
(refined, allCaptures)
425+
426+
/** Augment result type of constructor with refinements and captures.
427+
* @param core The result type of the constructor
428+
* @param initCs The initial capture set to add, not yet counting capture sets from arguments
429+
*/
426430
def augmentConstructorType(core: Type, initCs: CaptureSet): Type = core match
427431
case core: MethodType =>
428432
// more parameters to follow; augment result type
@@ -435,13 +439,8 @@ class CheckCaptures extends Recheck, SymTransformer:
435439
val (refined, cs) = addParamArgRefinements(core, initCs)
436440
refined.capturing(cs)
437441

438-
augmentConstructorType(ownType, CaptureSet.empty) match
439-
case augmented: MethodType =>
440-
augmented
441-
case augmented =>
442-
// add capture sets of class and constructor to final result of constructor call
443-
augmented.capturing(capturedVars(cls) ++ capturedVars(sym))
444-
.showing(i"constr type $mt with $argTypes%, % in $cls = $result", capt)
442+
augmentConstructorType(ownType, capturedVars(cls) ++ capturedVars(sym))
443+
.showing(i"constr type $mt with $argTypes%, % in $cls = $result", capt)
445444
else ownType
446445
end instantiate
447446

0 commit comments

Comments
 (0)