File tree 3 files changed +18
-3
lines changed
compiler/src/dotty/tools/dotc
3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -197,7 +197,7 @@ extends tpd.TreeTraverser:
197
197
val mt = ContextualMethodType (paramName :: Nil )(
198
198
_ => paramType :: Nil ,
199
199
mt => if isLast then res else expandThrowsAlias(res, mt :: encl))
200
- val fntpe = RefinedType ( defn.PolyFunctionClass .typeRef, nme.apply, mt)
200
+ val fntpe = defn.PolyFunctionOf ( mt)
201
201
if ! encl.isEmpty && isLast then
202
202
val cs = CaptureSet (encl.map(_.paramRefs.head)* )
203
203
CapturingType (fntpe, cs, boxed = false )
Original file line number Diff line number Diff line change @@ -1130,6 +1130,12 @@ class Definitions {
1130
1130
}
1131
1131
1132
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
+
1133
1139
/** Matches a refined `PolyFunction` type and extracts the apply info.
1134
1140
*
1135
1141
* Pattern: `PolyFunction { def apply: $mt }`
@@ -1139,6 +1145,15 @@ class Definitions {
1139
1145
if parent.derivesFrom(defn.PolyFunctionClass ) =>
1140
1146
Some (mt)
1141
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)
1142
1157
}
1143
1158
1144
1159
object PartialFunctionOf {
Original file line number Diff line number Diff line change @@ -1886,13 +1886,13 @@ object Types {
1886
1886
formals1 mapConserve (_.translateFromRepeated(toArray = isJava)),
1887
1887
result1, isContextual)
1888
1888
if mt.hasErasedParams then
1889
- RefinedType ( defn.PolyFunctionType , nme.apply, mt)
1889
+ defn.PolyFunctionOf ( mt)
1890
1890
else if alwaysDependent || mt.isResultDependent then
1891
1891
RefinedType (nonDependentFunType, nme.apply, mt)
1892
1892
else nonDependentFunType
1893
1893
case poly @ PolyType (_, mt : MethodType ) =>
1894
1894
assert(! mt.isParamDependent)
1895
- RefinedType ( defn.PolyFunctionType , nme.apply, poly)
1895
+ defn.PolyFunctionOf ( poly)
1896
1896
}
1897
1897
1898
1898
/** The signature of this type. This is by default NotAMethod,
You can’t perform that action at this time.
0 commit comments