@@ -623,15 +623,19 @@ class CheckCaptures extends Recheck, SymTransformer:
623623 i " adapting $actual $arrow $expected"
624624
625625 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)
629632 case actual =>
630- (actual, CaptureSet (), false )
633+ (( actual, CaptureSet (), false ), reconstruct )
631634
635+ val (actualTp, recon) = destructCapturingType(actual, x => x)
632636 val (parent1, cs1, isBoxed1) = adaptCapturingType(actualTp, expected, covariant)
633637
634- CapturingType (parent1, cs1, isBoxed1)
638+ recon( CapturingType (parent1, cs1, isBoxed1) )
635639 }
636640
637641 def adaptCapturingType (actual : (Type , CaptureSet , Boolean ),
@@ -652,7 +656,8 @@ class CheckCaptures extends Recheck, SymTransformer:
652656 (aargs1, ares1) =>
653657 rinfo.derivedLambdaType(paramInfos = aargs1, resType = ares1)
654658 .toFunctionType(isJava = false , alwaysDependent = true ))
655- case _ => (parent, cs)
659+ case _ =>
660+ (parent, cs)
656661 }
657662
658663 if needsAdaptation then
0 commit comments