@@ -1872,7 +1872,7 @@ object Types {
1872
1872
* when forming the function type.
1873
1873
* @param alwaysDependent if true, always create a dependent function type.
1874
1874
*/
1875
- def toFunctionType (isJava : Boolean , dropLast : Int = 0 , alwaysDependent : Boolean = false )(using Context ): Type = this match {
1875
+ def toFunctionType (isJava : Boolean = false , dropLast : Int = 0 , alwaysDependent : Boolean = false )(using Context ): Type = this match {
1876
1876
case mt : MethodType =>
1877
1877
assert(! mt.isParamDependent)
1878
1878
def nonDependentFunType =
@@ -1886,15 +1886,26 @@ object Types {
1886
1886
formals1 mapConserve (_.translateFromRepeated(toArray = isJava)),
1887
1887
result1, isContextual)
1888
1888
if mt.hasErasedParams then
1889
- defn.PolyFunctionOf (mt)
1889
+ assert(isValidPolyFunctionInfo(mt), s " Not a valid PolyFunction refinement: $mt" )
1890
+ RefinedType (defn.PolyFunctionType , nme.apply, mt)
1890
1891
else if alwaysDependent || mt.isResultDependent then
1891
1892
RefinedType (nonDependentFunType, nme.apply, mt)
1892
1893
else nonDependentFunType
1893
- case poly @ PolyType (_, mt : MethodType ) =>
1894
- assert(! mt.isParamDependent )
1895
- defn.PolyFunctionOf ( poly)
1894
+ case poly : PolyType =>
1895
+ assert(isValidPolyFunctionInfo(poly), s " Not a valid PolyFunction refinement: $poly " )
1896
+ RefinedType ( defn.PolyFunctionType , nme.apply, poly)
1896
1897
}
1897
1898
1899
+ private def isValidPolyFunctionInfo (info : Type )(using Context ): Boolean =
1900
+ def isValidMethodType (info : Type ) = info match
1901
+ case info : MethodType =>
1902
+ ! info.resType.isInstanceOf [MethodOrPoly ] // Has only one parameter list
1903
+ && ! info.isParamDependent
1904
+ case _ => false
1905
+ info match
1906
+ case info : PolyType => isValidMethodType(info.resType)
1907
+ case _ => isValidMethodType(info)
1908
+
1898
1909
/** The signature of this type. This is by default NotAMethod,
1899
1910
* but is overridden for PolyTypes, MethodTypes, and TermRef types.
1900
1911
* (the reason why we deviate from the "final-method-with-pattern-match-in-base-class"
0 commit comments