@@ -1112,12 +1112,12 @@ class Definitions {
1112
1112
def apply (args : List [Type ], resultType : Type , isContextual : Boolean = false )(using Context ): Type =
1113
1113
val mt = MethodType .companion(isContextual, false )(args, resultType)
1114
1114
if mt.hasErasedParams then
1115
- RefinedType (ErasedFunctionClass .typeRef, nme.apply, mt)
1115
+ RefinedType (PolyFunctionClass .typeRef, nme.apply, mt)
1116
1116
else
1117
1117
FunctionType (args.length, isContextual).appliedTo(args ::: resultType :: Nil )
1118
1118
def unapply (ft : Type )(using Context ): Option [(List [Type ], Type , Boolean )] = {
1119
1119
ft.dealias match
1120
- case ErasedFunctionOf (mt) =>
1120
+ case PolyFunctionOf (mt : MethodType ) =>
1121
1121
Some (mt.paramInfos, mt.resType, mt.isContextualMethod)
1122
1122
case dft =>
1123
1123
val tsym = dft.typeSymbol
@@ -1129,40 +1129,31 @@ class Definitions {
1129
1129
}
1130
1130
}
1131
1131
1132
- object PolyOrErasedFunctionOf {
1133
- /** Matches a refined `PolyFunction` or `ErasedFunction` type and extracts the apply info.
1134
- *
1135
- * Pattern: `(PolyFunction | ErasedFunction) { def apply: $mt }`
1136
- */
1137
- def unapply (ft : Type )(using Context ): Option [MethodicType ] = ft.dealias match
1138
- case RefinedType (parent, nme.apply, mt : MethodicType )
1139
- if parent.derivesFrom(defn.PolyFunctionClass ) || parent.derivesFrom(defn.ErasedFunctionClass ) =>
1140
- Some (mt)
1141
- case _ => None
1142
- }
1143
-
1144
1132
object PolyFunctionOf {
1133
+
1134
+ /** Creates a refined `PolyFunction` with an `apply` method with the given info. */
1135
+ def apply (mt : MethodOrPoly )(using Context ): Type =
1136
+ assert(isValidPolyFunctionInfo(mt), s " Not a valid PolyFunction refinement: $mt" )
1137
+ RefinedType (PolyFunctionClass .typeRef, nme.apply, mt)
1138
+
1145
1139
/** Matches a refined `PolyFunction` type and extracts the apply info.
1146
1140
*
1147
- * Pattern: `PolyFunction { def apply: $pt }`
1141
+ * Pattern: `PolyFunction { def apply: $mt }`
1148
1142
*/
1149
- def unapply (ft : Type )(using Context ): Option [PolyType ] = ft.dealias match
1150
- case RefinedType (parent, nme.apply, pt : PolyType )
1143
+ def unapply (ft : Type )(using Context ): Option [MethodicType ] = ft.dealias match
1144
+ case RefinedType (parent, nme.apply, mt : MethodicType )
1151
1145
if parent.derivesFrom(defn.PolyFunctionClass ) =>
1152
- Some (pt)
1153
- case _ => None
1154
- }
1155
-
1156
- object ErasedFunctionOf {
1157
- /** Matches a refined `ErasedFunction` type and extracts the apply info.
1158
- *
1159
- * Pattern: `ErasedFunction { def apply: $mt }`
1160
- */
1161
- def unapply (ft : Type )(using Context ): Option [MethodType ] = ft.dealias match
1162
- case RefinedType (parent, nme.apply, mt : MethodType )
1163
- if parent.derivesFrom(defn.ErasedFunctionClass ) =>
1164
1146
Some (mt)
1165
1147
case _ => None
1148
+
1149
+ private def isValidPolyFunctionInfo (info : Type )(using Context ): Boolean =
1150
+ def isValidMethodType (info : Type ) = info match
1151
+ case info : MethodType =>
1152
+ ! info.resType.isInstanceOf [MethodOrPoly ] // Has only one parameter list
1153
+ case _ => false
1154
+ info match
1155
+ case info : PolyType => isValidMethodType(info.resType)
1156
+ case _ => isValidMethodType(info)
1166
1157
}
1167
1158
1168
1159
object PartialFunctionOf {
@@ -1514,9 +1505,6 @@ class Definitions {
1514
1505
lazy val PolyFunctionClass = requiredClass(" scala.PolyFunction" )
1515
1506
def PolyFunctionType = PolyFunctionClass .typeRef
1516
1507
1517
- lazy val ErasedFunctionClass = requiredClass(" scala.runtime.ErasedFunction" )
1518
- def ErasedFunctionType = ErasedFunctionClass .typeRef
1519
-
1520
1508
/** If `cls` is a class in the scala package, its name, otherwise EmptyTypeName */
1521
1509
def scalaClassName (cls : Symbol )(using Context ): TypeName = cls.denot match
1522
1510
case clsd : ClassDenotation if clsd.owner eq ScalaPackageClass =>
@@ -1579,8 +1567,6 @@ class Definitions {
1579
1567
/** Is a synthetic function class
1580
1568
* - FunctionN for N > 22
1581
1569
* - ContextFunctionN for N >= 0
1582
- * - ErasedFunctionN for N > 0
1583
- * - ErasedContextFunctionN for N > 0
1584
1570
*/
1585
1571
def isSyntheticFunctionClass (cls : Symbol ): Boolean = scalaClassName(cls).isSyntheticFunction
1586
1572
@@ -1596,8 +1582,6 @@ class Definitions {
1596
1582
* - FunctionN for 22 > N >= 0 remains as FunctionN
1597
1583
* - ContextFunctionN for N > 22 becomes FunctionXXL
1598
1584
* - ContextFunctionN for N <= 22 becomes FunctionN
1599
- * - ErasedFunctionN becomes Function0
1600
- * - ImplicitErasedFunctionN becomes Function0
1601
1585
* - anything else becomes a NoType
1602
1586
*/
1603
1587
def functionTypeErasure (cls : Symbol ): Type =
@@ -1756,13 +1740,11 @@ class Definitions {
1756
1740
/** Returns whether `tp` is an instance or a refined instance of:
1757
1741
* - scala.FunctionN
1758
1742
* - scala.ContextFunctionN
1759
- * - ErasedFunction
1760
1743
* - PolyFunction
1761
1744
*/
1762
1745
def isFunctionType (tp : Type )(using Context ): Boolean =
1763
1746
isFunctionNType(tp)
1764
1747
|| tp.derivesFrom(defn.PolyFunctionClass ) // TODO check for refinement?
1765
- || tp.derivesFrom(defn.ErasedFunctionClass ) // TODO check for refinement?
1766
1748
1767
1749
private def withSpecMethods (cls : ClassSymbol , bases : List [Name ], paramTypes : Set [TypeRef ]) =
1768
1750
if ! ctx.settings.Yscala2Stdlib .value then
@@ -1866,7 +1848,7 @@ class Definitions {
1866
1848
tp.stripTypeVar.dealias match
1867
1849
case tp1 : TypeParamRef if ctx.typerState.constraint.contains(tp1) =>
1868
1850
asContextFunctionType(TypeComparer .bounds(tp1).hiBound)
1869
- case tp1 @ ErasedFunctionOf (mt) if mt.isContextualMethod =>
1851
+ case tp1 @ PolyFunctionOf (mt : MethodType ) if mt.isContextualMethod =>
1870
1852
tp1
1871
1853
case tp1 =>
1872
1854
if tp1.typeSymbol.name.isContextFunction && isFunctionNType(tp1) then tp1
@@ -1886,21 +1868,14 @@ class Definitions {
1886
1868
atPhase(erasurePhase)(unapply(tp))
1887
1869
else
1888
1870
asContextFunctionType(tp) match
1889
- case ErasedFunctionOf (mt) =>
1871
+ case PolyFunctionOf (mt : MethodType ) =>
1890
1872
Some ((mt.paramInfos, mt.resType, mt.erasedParams))
1891
1873
case tp1 if tp1.exists =>
1892
1874
val args = tp1.functionArgInfos
1893
- val erasedParams = erasedFunctionParameters( tp1)
1875
+ val erasedParams = List .fill(functionArity( tp1)) { false }
1894
1876
Some ((args.init, args.last, erasedParams))
1895
1877
case _ => None
1896
1878
1897
- /* Returns a list of erased booleans marking whether parameters are erased, for a function type. */
1898
- def erasedFunctionParameters (tp : Type )(using Context ): List [Boolean ] = tp.dealias match {
1899
- case ErasedFunctionOf (mt) => mt.erasedParams
1900
- case tp if isFunctionNType(tp) => List .fill(functionArity(tp)) { false }
1901
- case _ => Nil
1902
- }
1903
-
1904
1879
/** A whitelist of Scala-2 classes that are known to be pure */
1905
1880
def isAssuredNoInits (sym : Symbol ): Boolean =
1906
1881
(sym `eq` SomeClass ) || isTupleClass(sym)
0 commit comments