@@ -1114,7 +1114,7 @@ class Definitions {
1114
1114
FunctionType (args.length, isContextual).appliedTo(args ::: resultType :: Nil )
1115
1115
def unapply (ft : Type )(using Context ): Option [(List [Type ], Type , Boolean )] = {
1116
1116
ft.dealias match
1117
- case RefinedType (parent, nme.apply, mt : MethodType ) if isErasedFunctionType(parent ) =>
1117
+ case PolyOrErasedFunctionOf ( mt : MethodType ) =>
1118
1118
Some (mt.paramInfos, mt.resType, mt.isContextualMethod)
1119
1119
case _ =>
1120
1120
val tsym = ft.dealias.typeSymbol
@@ -1126,6 +1126,18 @@ class Definitions {
1126
1126
}
1127
1127
}
1128
1128
1129
+ object PolyOrErasedFunctionOf {
1130
+ /** Matches a refined `PolyFunction` or `ErasedFunction` type and extracts the apply info.
1131
+ *
1132
+ * Pattern: `(PolyFunction | ErasedFunction) { def apply: $mt }`
1133
+ */
1134
+ def unapply (ft : Type )(using Context ): Option [MethodicType ] = ft.dealias match
1135
+ case RefinedType (parent, nme.apply, mt : MethodicType )
1136
+ if parent.derivesFrom(defn.PolyFunctionClass ) || parent.derivesFrom(defn.ErasedFunctionClass ) =>
1137
+ Some (mt)
1138
+ case _ => None
1139
+ }
1140
+
1129
1141
object PartialFunctionOf {
1130
1142
def apply (arg : Type , result : Type )(using Context ): Type =
1131
1143
PartialFunctionClass .typeRef.appliedTo(arg :: result :: Nil )
@@ -1713,26 +1725,16 @@ class Definitions {
1713
1725
def isFunctionNType (tp : Type )(using Context ): Boolean =
1714
1726
isNonRefinedFunction(tp.dropDependentRefinement)
1715
1727
1716
- /** Does `tp` derive from `PolyFunction` or `ErasedFunction`? */
1717
- def isPolyOrErasedFunctionType (tp : Type )(using Context ): Boolean =
1718
- isPolyFunctionType(tp) || isErasedFunctionType(tp)
1719
-
1720
- /** Does `tp` derive from `PolyFunction`? */
1721
- def isPolyFunctionType (tp : Type )(using Context ): Boolean =
1722
- tp.derivesFrom(defn.PolyFunctionClass )
1723
-
1724
- /** Does `tp` derive from `ErasedFunction`? */
1725
- def isErasedFunctionType (tp : Type )(using Context ): Boolean =
1726
- tp.derivesFrom(defn.ErasedFunctionClass )
1727
-
1728
1728
/** Returns whether `tp` is an instance or a refined instance of:
1729
1729
* - scala.FunctionN
1730
1730
* - scala.ContextFunctionN
1731
1731
* - ErasedFunction
1732
1732
* - PolyFunction
1733
1733
*/
1734
1734
def isFunctionType (tp : Type )(using Context ): Boolean =
1735
- isFunctionNType(tp) || isPolyOrErasedFunctionType(tp)
1735
+ isFunctionNType(tp)
1736
+ || tp.derivesFrom(defn.PolyFunctionClass ) // TODO check for refinement?
1737
+ || tp.derivesFrom(defn.ErasedFunctionClass ) // TODO check for refinement?
1736
1738
1737
1739
private def withSpecMethods (cls : ClassSymbol , bases : List [Name ], paramTypes : Set [TypeRef ]) =
1738
1740
if ! ctx.settings.Yscala2Stdlib .value then
@@ -1836,7 +1838,7 @@ class Definitions {
1836
1838
tp.stripTypeVar.dealias match
1837
1839
case tp1 : TypeParamRef if ctx.typerState.constraint.contains(tp1) =>
1838
1840
asContextFunctionType(TypeComparer .bounds(tp1).hiBound)
1839
- case tp1 @ RefinedType (parent, nme.apply, mt : MethodType ) if isErasedFunctionType(parent) && mt.isContextualMethod =>
1841
+ case tp1 @ PolyOrErasedFunctionOf ( mt : MethodType ) if mt.isContextualMethod =>
1840
1842
tp1
1841
1843
case tp1 =>
1842
1844
if tp1.typeSymbol.name.isContextFunction && isFunctionNType(tp1) then tp1
@@ -1856,7 +1858,7 @@ class Definitions {
1856
1858
atPhase(erasurePhase)(unapply(tp))
1857
1859
else
1858
1860
asContextFunctionType(tp) match
1859
- case RefinedType (parent, nme.apply, mt : MethodType ) if isErasedFunctionType(parent ) =>
1861
+ case PolyOrErasedFunctionOf ( mt : MethodType ) =>
1860
1862
Some ((mt.paramInfos, mt.resType, mt.erasedParams))
1861
1863
case tp1 if tp1.exists =>
1862
1864
val args = tp1.functionArgInfos
0 commit comments