@@ -623,15 +623,19 @@ class CheckCaptures extends Recheck, SymTransformer:
623
623
i " adapting $actual $arrow $expected"
624
624
625
625
def adapt (actual : Type , expected : Type , covariant : Boolean ): Type = trace(adaptInfo(actual, expected, covariant), recheckr, show = true ) {
626
- val actualTp = actual match
627
- case actual @ CapturingType (parent, cs) =>
628
- (parent, cs, actual.isBoxed)
626
+ def destructCapturingType (tp : Type , reconstruct : Type => Type ): ((Type , CaptureSet , Boolean ), Type => Type ) = tp match
627
+ case tp @ CapturingType (parent, cs) =>
628
+ if parent.isCapturingType then
629
+ destructCapturingType(parent, res => reconstruct(tp.derivedCapturingType(res, cs)))
630
+ else
631
+ ((parent, cs, tp.isBoxed), reconstruct)
629
632
case actual =>
630
- (actual, CaptureSet (), false )
633
+ (( actual, CaptureSet (), false ), reconstruct )
631
634
635
+ val (actualTp, recon) = destructCapturingType(actual, x => x)
632
636
val (parent1, cs1, isBoxed1) = adaptCapturingType(actualTp, expected, covariant)
633
637
634
- CapturingType (parent1, cs1, isBoxed1)
638
+ recon( CapturingType (parent1, cs1, isBoxed1) )
635
639
}
636
640
637
641
def adaptCapturingType (actual : (Type , CaptureSet , Boolean ),
@@ -652,7 +656,8 @@ class CheckCaptures extends Recheck, SymTransformer:
652
656
(aargs1, ares1) =>
653
657
rinfo.derivedLambdaType(paramInfos = aargs1, resType = ares1)
654
658
.toFunctionType(isJava = false , alwaysDependent = true ))
655
- case _ => (parent, cs)
659
+ case _ =>
660
+ (parent, cs)
656
661
}
657
662
658
663
if needsAdaptation then
0 commit comments