@@ -1108,7 +1108,7 @@ class Definitions {
1108
1108
FunctionType (args.length, isContextual).appliedTo(args ::: resultType :: Nil )
1109
1109
def unapply (ft : Type )(using Context ): Option [(List [Type ], Type , Boolean )] = {
1110
1110
ft.dealias match
1111
- case RefinedType (parent, nme.apply, mt : MethodType ) if isErasedFunctionType(parent ) =>
1111
+ case ErasedFunctionOf (mt ) =>
1112
1112
Some (mt.paramInfos, mt.resType, mt.isContextualMethod)
1113
1113
case _ =>
1114
1114
val tsym = ft.dealias.typeSymbol
@@ -1120,6 +1120,42 @@ class Definitions {
1120
1120
}
1121
1121
}
1122
1122
1123
+ object PolyOrErasedFunctionOf {
1124
+ /** Matches a refined `PolyFunction` or `ErasedFunction` type and extracts the apply info.
1125
+ *
1126
+ * Pattern: `(PolyFunction | ErasedFunction) { def apply: $mt }`
1127
+ */
1128
+ def unapply (ft : Type )(using Context ): Option [MethodicType ] = ft.dealias match
1129
+ case RefinedType (parent, nme.apply, mt : MethodicType )
1130
+ if parent.derivesFrom(defn.PolyFunctionClass ) || parent.derivesFrom(defn.ErasedFunctionClass ) =>
1131
+ Some (mt)
1132
+ case _ => None
1133
+ }
1134
+
1135
+ object PolyFunctionOf {
1136
+ /** Matches a refined `PolyFunction` type and extracts the apply info.
1137
+ *
1138
+ * Pattern: `PolyFunction { def apply: $pt }`
1139
+ */
1140
+ def unapply (ft : Type )(using Context ): Option [PolyType ] = ft.dealias match
1141
+ case RefinedType (parent, nme.apply, pt : PolyType )
1142
+ if parent.derivesFrom(defn.PolyFunctionClass ) =>
1143
+ Some (pt)
1144
+ case _ => None
1145
+ }
1146
+
1147
+ object ErasedFunctionOf {
1148
+ /** Matches a refined `ErasedFunction` type and extracts the apply info.
1149
+ *
1150
+ * Pattern: `ErasedFunction { def apply: $mt }`
1151
+ */
1152
+ def unapply (ft : Type )(using Context ): Option [MethodType ] = ft.dealias match
1153
+ case RefinedType (parent, nme.apply, mt : MethodType )
1154
+ if parent.derivesFrom(defn.ErasedFunctionClass ) =>
1155
+ Some (mt)
1156
+ case _ => None
1157
+ }
1158
+
1123
1159
object PartialFunctionOf {
1124
1160
def apply (arg : Type , result : Type )(using Context ): Type =
1125
1161
PartialFunctionClass .typeRef.appliedTo(arg :: result :: Nil )
@@ -1705,26 +1741,16 @@ class Definitions {
1705
1741
def isFunctionNType (tp : Type )(using Context ): Boolean =
1706
1742
isNonRefinedFunction(tp.dropDependentRefinement)
1707
1743
1708
- /** Does `tp` derive from `PolyFunction` or `ErasedFunction`? */
1709
- def isPolyOrErasedFunctionType (tp : Type )(using Context ): Boolean =
1710
- isPolyFunctionType(tp) || isErasedFunctionType(tp)
1711
-
1712
- /** Does `tp` derive from `PolyFunction`? */
1713
- def isPolyFunctionType (tp : Type )(using Context ): Boolean =
1714
- tp.derivesFrom(defn.PolyFunctionClass )
1715
-
1716
- /** Does `tp` derive from `ErasedFunction`? */
1717
- def isErasedFunctionType (tp : Type )(using Context ): Boolean =
1718
- tp.derivesFrom(defn.ErasedFunctionClass )
1719
-
1720
1744
/** Returns whether `tp` is an instance or a refined instance of:
1721
1745
* - scala.FunctionN
1722
1746
* - scala.ContextFunctionN
1723
1747
* - ErasedFunction
1724
1748
* - PolyFunction
1725
1749
*/
1726
1750
def isFunctionType (tp : Type )(using Context ): Boolean =
1727
- isFunctionNType(tp) || isPolyOrErasedFunctionType(tp)
1751
+ isFunctionNType(tp)
1752
+ || tp.derivesFrom(defn.PolyFunctionClass ) // TODO check for refinement?
1753
+ || tp.derivesFrom(defn.ErasedFunctionClass ) // TODO check for refinement?
1728
1754
1729
1755
private def withSpecMethods (cls : ClassSymbol , bases : List [Name ], paramTypes : Set [TypeRef ]) =
1730
1756
for base <- bases; tp <- paramTypes do
@@ -1825,7 +1851,7 @@ class Definitions {
1825
1851
tp.stripTypeVar.dealias match
1826
1852
case tp1 : TypeParamRef if ctx.typerState.constraint.contains(tp1) =>
1827
1853
asContextFunctionType(TypeComparer .bounds(tp1).hiBound)
1828
- case tp1 @ RefinedType (parent, nme.apply, mt : MethodType ) if isErasedFunctionType(parent) && mt.isContextualMethod =>
1854
+ case tp1 @ ErasedFunctionOf (mt ) if mt.isContextualMethod =>
1829
1855
tp1
1830
1856
case tp1 =>
1831
1857
if tp1.typeSymbol.name.isContextFunction && isFunctionNType(tp1) then tp1
@@ -1845,7 +1871,7 @@ class Definitions {
1845
1871
atPhase(erasurePhase)(unapply(tp))
1846
1872
else
1847
1873
asContextFunctionType(tp) match
1848
- case RefinedType (parent, nme.apply, mt : MethodType ) if isErasedFunctionType(parent ) =>
1874
+ case ErasedFunctionOf (mt ) =>
1849
1875
Some ((mt.paramInfos, mt.resType, mt.erasedParams))
1850
1876
case tp1 if tp1.exists =>
1851
1877
val args = tp1.functionArgInfos
@@ -1855,7 +1881,7 @@ class Definitions {
1855
1881
1856
1882
/* Returns a list of erased booleans marking whether parameters are erased, for a function type. */
1857
1883
def erasedFunctionParameters (tp : Type )(using Context ): List [Boolean ] = tp.dealias match {
1858
- case RefinedType (parent, nme.apply, mt : MethodType ) => mt.erasedParams
1884
+ case ErasedFunctionOf (mt ) => mt.erasedParams
1859
1885
case tp if isFunctionNType(tp) => List .fill(functionArity(tp)) { false }
1860
1886
case _ => Nil
1861
1887
}
0 commit comments