@@ -195,7 +195,7 @@ class CheckCaptures extends Recheck, SymTransformer:
195
195
capt.println(i " solving $t" )
196
196
refs.solve()
197
197
traverse(parent)
198
- case t @ RefinedType (_, nme.apply, rinfo) if defn.isFunctionType(t ) =>
198
+ case defn.RefinedFunctionOf (rinfo ) =>
199
199
traverse(rinfo)
200
200
case tp : TypeVar =>
201
201
case tp : TypeRef =>
@@ -302,8 +302,8 @@ class CheckCaptures extends Recheck, SymTransformer:
302
302
t
303
303
case _ =>
304
304
val t1 = t match
305
- case t @ RefinedType (parent, rname, rinfo : MethodType ) if defn.isFunctionType(t ) =>
306
- t.derivedRefinedType(parent, rname , this (rinfo))
305
+ case t @ defn. RefinedFunctionOf ( rinfo : MethodType ) =>
306
+ t.derivedRefinedType(t. parent, t.refinedName , this (rinfo))
307
307
case _ =>
308
308
mapOver(t)
309
309
if variance > 0 then t1
@@ -408,10 +408,10 @@ class CheckCaptures extends Recheck, SymTransformer:
408
408
else if meth == defn.Caps_unsafeUnbox then
409
409
mapArgUsing(_.forceBoxStatus(false ))
410
410
else if meth == defn.Caps_unsafeBoxFunArg then
411
- mapArgUsing :
412
- case defn.FunctionOf (paramtpe :: Nil , restpe, isContextual ) =>
413
- defn. FunctionOf (paramtpe .forceBoxStatus(true ) :: Nil , restpe, isContextual )
414
-
411
+ mapArgUsing : tp =>
412
+ val defn .FunctionOf (mt : MethodType ) = tp.dealias : @ unchecked
413
+ mt.derivedLambdaType(resType = mt.resType .forceBoxStatus(true ))
414
+ .toFunctionType()
415
415
else
416
416
super .recheckApply(tree, pt) match
417
417
case appType @ CapturingType (appType1, refs) =>
@@ -502,8 +502,9 @@ class CheckCaptures extends Recheck, SymTransformer:
502
502
block match
503
503
case closureDef(mdef) =>
504
504
pt.dealias match
505
- case defn.FunctionOf (ptformals, _, _)
506
- if ptformals.nonEmpty && ptformals.forall(_.captureSet.isAlwaysEmpty) =>
505
+ case defn.FunctionOf (mt0 : MethodType )
506
+ if mt0.paramInfos.nonEmpty && mt0.paramInfos.forall(_.captureSet.isAlwaysEmpty) =>
507
+ val ptformals = mt0.paramInfos
507
508
// Redo setup of the anonymous function so that formal parameters don't
508
509
// get capture sets. This is important to avoid false widenings to `cap`
509
510
// when taking the base type of the actual closures's dependent function
@@ -696,21 +697,19 @@ class CheckCaptures extends Recheck, SymTransformer:
696
697
// println(i"check conforms $actual1 <<< $expected1")
697
698
super .checkConformsExpr(actual1, expected1, tree)
698
699
699
- private def toDepFun (args : List [Type ], resultType : Type , isContextual : Boolean )(using Context ): Type =
700
- MethodType .companion(isContextual = isContextual)(args, resultType)
701
- .toFunctionType(isJava = false , alwaysDependent = true )
702
-
703
700
/** Turn `expected` into a dependent function when `actual` is dependent. */
704
701
private def alignDependentFunction (expected : Type , actual : Type )(using Context ): Type =
705
702
def recur (expected : Type ): Type = expected.dealias match
706
703
case expected0 @ CapturingType (eparent, refs) =>
707
704
val eparent1 = recur(eparent)
708
705
if eparent1 eq eparent then expected
709
706
else CapturingType (eparent1, refs, boxed = expected0.isBoxed)
710
- case expected @ defn.FunctionOf (args, resultType, isContextual)
711
- if defn.isNonRefinedFunction(expected) && defn.isFunctionNType(actual) && ! defn.isNonRefinedFunction(actual) =>
712
- val expected1 = toDepFun(args, resultType, isContextual)
713
- expected1
707
+ case defn.FunctionOf (mt : MethodType ) =>
708
+ actual.dealias match
709
+ case defn.FunctionOf (mt2 : MethodType ) if mt2.isResultDependent =>
710
+ mt.toFunctionType(alwaysDependent = true )
711
+ case _ =>
712
+ expected
714
713
case _ =>
715
714
expected
716
715
recur(expected)
@@ -781,9 +780,8 @@ class CheckCaptures extends Recheck, SymTransformer:
781
780
782
781
try
783
782
val (eargs, eres) = expected.dealias.stripCapturing match
784
- case defn.FunctionOf (eargs, eres, _) => (eargs, eres)
785
783
case expected : MethodType => (expected.paramInfos, expected.resType)
786
- case expected @ RefinedType (_, _, rinfo : MethodType ) if defn.isFunctionNType(expected) => (rinfo .paramInfos, rinfo .resType)
784
+ case defn. FunctionOf ( mt : MethodType ) => (mt .paramInfos, mt .resType)
787
785
case _ => (aargs.map(_ => WildcardType ), WildcardType )
788
786
val aargs1 = aargs.zipWithConserve(eargs) { (aarg, earg) => adapt(aarg, earg, ! covariant) }
789
787
val ares1 = adapt(ares, eres, covariant)
@@ -808,7 +806,7 @@ class CheckCaptures extends Recheck, SymTransformer:
808
806
809
807
try
810
808
val eres = expected.dealias.stripCapturing match
811
- case RefinedType (_, _, rinfo : PolyType ) => rinfo.resType
809
+ case defn. PolyFunctionOf ( rinfo : PolyType ) => rinfo.resType
812
810
case expected : PolyType => expected.resType
813
811
case _ => WildcardType
814
812
@@ -842,26 +840,26 @@ class CheckCaptures extends Recheck, SymTransformer:
842
840
843
841
// Adapt the inner shape type: get the adapted shape type, and the capture set leaked during adaptation
844
842
val (styp1, leaked) = styp match {
845
- case actual @ AppliedType (tycon, args) if defn.isNonRefinedFunction (actual) =>
843
+ case actual @ AppliedType (tycon, args) if defn.isFunctionNType (actual) =>
846
844
adaptFun(actual, args.init, args.last, expected, covariant, insertBox,
847
845
(aargs1, ares1) => actual.derivedAppliedType(tycon, aargs1 :+ ares1))
848
- case actual @ RefinedType (_, _, rinfo : MethodType ) if defn.isFunctionType(actual ) =>
846
+ case actual @ defn. RefinedFunctionOf ( rinfo : MethodType ) =>
849
847
// TODO Find a way to combine handling of generic and dependent function types (here and elsewhere)
850
848
adaptFun(actual, rinfo.paramInfos, rinfo.resType, expected, covariant, insertBox,
851
849
(aargs1, ares1) =>
852
850
rinfo.derivedLambdaType(paramInfos = aargs1, resType = ares1)
853
- .toFunctionType(isJava = false , alwaysDependent = true ))
854
- case actual : MethodType =>
855
- adaptFun(actual, actual.paramInfos, actual.resType, expected, covariant, insertBox,
856
- (aargs1, ares1) =>
857
- actual.derivedLambdaType(paramInfos = aargs1, resType = ares1))
858
- case actual @ RefinedType (p, nme, rinfo : PolyType ) if defn.isFunctionType(actual) =>
851
+ .toFunctionType(alwaysDependent = true ))
852
+ case actual @ defn.RefinedFunctionOf (rinfo : PolyType ) =>
859
853
adaptTypeFun(actual, rinfo.resType, expected, covariant, insertBox,
860
854
ares1 =>
861
855
val rinfo1 = rinfo.derivedLambdaType(rinfo.paramNames, rinfo.paramInfos, ares1)
862
- val actual1 = actual.derivedRefinedType(p, nme , rinfo1)
856
+ val actual1 = actual.derivedRefinedType(actual.parent, actual.refinedName , rinfo1)
863
857
actual1
864
858
)
859
+ case actual : MethodType =>
860
+ adaptFun(actual, actual.paramInfos, actual.resType, expected, covariant, insertBox,
861
+ (aargs1, ares1) =>
862
+ actual.derivedLambdaType(paramInfos = aargs1, resType = ares1))
865
863
case _ =>
866
864
(styp, CaptureSet ())
867
865
}
@@ -1080,7 +1078,7 @@ class CheckCaptures extends Recheck, SymTransformer:
1080
1078
case CapturingType (parent, refs) =>
1081
1079
healCaptureSet(refs)
1082
1080
traverse(parent)
1083
- case tp @ RefinedType (parent, rname, rinfo : MethodType ) if defn.isFunctionType(tp ) =>
1081
+ case defn. RefinedFunctionOf ( rinfo : MethodType ) =>
1084
1082
traverse(rinfo)
1085
1083
case tp : TermLambda =>
1086
1084
val saved = allowed
0 commit comments