@@ -195,7 +195,7 @@ class CheckCaptures extends Recheck, SymTransformer:
195195 capt.println(i " solving $t" )
196196 refs.solve()
197197 traverse(parent)
198- case t @ RefinedType (_, nme.apply, rinfo) if defn.isFunctionType(t ) =>
198+ case defn.RefinedFunctionOf (rinfo ) =>
199199 traverse(rinfo)
200200 case tp : TypeVar =>
201201 case tp : TypeRef =>
@@ -302,8 +302,8 @@ class CheckCaptures extends Recheck, SymTransformer:
302302 t
303303 case _ =>
304304 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))
307307 case _ =>
308308 mapOver(t)
309309 if variance > 0 then t1
@@ -408,10 +408,10 @@ class CheckCaptures extends Recheck, SymTransformer:
408408 else if meth == defn.Caps_unsafeUnbox then
409409 mapArgUsing(_.forceBoxStatus(false ))
410410 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()
415415 else
416416 super .recheckApply(tree, pt) match
417417 case appType @ CapturingType (appType1, refs) =>
@@ -502,8 +502,9 @@ class CheckCaptures extends Recheck, SymTransformer:
502502 block match
503503 case closureDef(mdef) =>
504504 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
507508 // Redo setup of the anonymous function so that formal parameters don't
508509 // get capture sets. This is important to avoid false widenings to `cap`
509510 // when taking the base type of the actual closures's dependent function
@@ -696,21 +697,19 @@ class CheckCaptures extends Recheck, SymTransformer:
696697 // println(i"check conforms $actual1 <<< $expected1")
697698 super .checkConformsExpr(actual1, expected1, tree)
698699
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-
703700 /** Turn `expected` into a dependent function when `actual` is dependent. */
704701 private def alignDependentFunction (expected : Type , actual : Type )(using Context ): Type =
705702 def recur (expected : Type ): Type = expected.dealias match
706703 case expected0 @ CapturingType (eparent, refs) =>
707704 val eparent1 = recur(eparent)
708705 if eparent1 eq eparent then expected
709706 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
714713 case _ =>
715714 expected
716715 recur(expected)
@@ -781,9 +780,8 @@ class CheckCaptures extends Recheck, SymTransformer:
781780
782781 try
783782 val (eargs, eres) = expected.dealias.stripCapturing match
784- case defn.FunctionOf (eargs, eres, _) => (eargs, eres)
785783 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)
787785 case _ => (aargs.map(_ => WildcardType ), WildcardType )
788786 val aargs1 = aargs.zipWithConserve(eargs) { (aarg, earg) => adapt(aarg, earg, ! covariant) }
789787 val ares1 = adapt(ares, eres, covariant)
@@ -808,7 +806,7 @@ class CheckCaptures extends Recheck, SymTransformer:
808806
809807 try
810808 val eres = expected.dealias.stripCapturing match
811- case RefinedType (_, _, rinfo : PolyType ) => rinfo.resType
809+ case defn. PolyFunctionOf ( rinfo : PolyType ) => rinfo.resType
812810 case expected : PolyType => expected.resType
813811 case _ => WildcardType
814812
@@ -842,26 +840,26 @@ class CheckCaptures extends Recheck, SymTransformer:
842840
843841 // Adapt the inner shape type: get the adapted shape type, and the capture set leaked during adaptation
844842 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) =>
846844 adaptFun(actual, args.init, args.last, expected, covariant, insertBox,
847845 (aargs1, ares1) => actual.derivedAppliedType(tycon, aargs1 :+ ares1))
848- case actual @ RefinedType (_, _, rinfo : MethodType ) if defn.isFunctionType(actual ) =>
846+ case actual @ defn. RefinedFunctionOf ( rinfo : MethodType ) =>
849847 // TODO Find a way to combine handling of generic and dependent function types (here and elsewhere)
850848 adaptFun(actual, rinfo.paramInfos, rinfo.resType, expected, covariant, insertBox,
851849 (aargs1, ares1) =>
852850 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 ) =>
859853 adaptTypeFun(actual, rinfo.resType, expected, covariant, insertBox,
860854 ares1 =>
861855 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)
863857 actual1
864858 )
859+ case actual : MethodType =>
860+ adaptFun(actual, actual.paramInfos, actual.resType, expected, covariant, insertBox,
861+ (aargs1, ares1) =>
862+ actual.derivedLambdaType(paramInfos = aargs1, resType = ares1))
865863 case _ =>
866864 (styp, CaptureSet ())
867865 }
@@ -1080,7 +1078,7 @@ class CheckCaptures extends Recheck, SymTransformer:
10801078 case CapturingType (parent, refs) =>
10811079 healCaptureSet(refs)
10821080 traverse(parent)
1083- case tp @ RefinedType (parent, rname, rinfo : MethodType ) if defn.isFunctionType(tp ) =>
1081+ case defn. RefinedFunctionOf ( rinfo : MethodType ) =>
10841082 traverse(rinfo)
10851083 case tp : TermLambda =>
10861084 val saved = allowed
0 commit comments