@@ -414,15 +414,19 @@ class CheckCaptures extends Recheck, SymTransformer:
414
414
* Second half: union of all capture sets of arguments to tracked parameters.
415
415
*/
416
416
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
420
420
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
+ */
426
430
def augmentConstructorType (core : Type , initCs : CaptureSet ): Type = core match
427
431
case core : MethodType =>
428
432
// more parameters to follow; augment result type
@@ -435,13 +439,8 @@ class CheckCaptures extends Recheck, SymTransformer:
435
439
val (refined, cs) = addParamArgRefinements(core, initCs)
436
440
refined.capturing(cs)
437
441
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)
445
444
else ownType
446
445
end instantiate
447
446
0 commit comments