Skip to content

Commit aca69bd

Browse files
committed
Refactor toFunctionType
1 parent 3ea39ea commit aca69bd

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,23 +1875,25 @@ object Types {
18751875
* @param alwaysDependent if true, always create a dependent function type.
18761876
*/
18771877
def toFunctionType(isJava: Boolean, dropLast: Int = 0, alwaysDependent: Boolean = false)(using Context): Type = this match {
1878-
case mt: MethodType if !mt.isParamDependent && !mt.hasErasedParams =>
1879-
val formals1 = if (dropLast == 0) mt.paramInfos else mt.paramInfos dropRight dropLast
1880-
val isContextual = mt.isContextualMethod && !ctx.erasedTypes
1881-
val result1 = mt.nonDependentResultApprox match {
1882-
case res: MethodType => res.toFunctionType(isJava)
1883-
case res => res
1884-
}
1885-
val funType = defn.FunctionOf(
1886-
formals1 mapConserve (_.translateFromRepeated(toArray = isJava)),
1887-
result1, isContextual)
1888-
if alwaysDependent || mt.isResultDependent then
1889-
RefinedType(funType, nme.apply, mt)
1890-
else funType
1891-
case mt: MethodType if !mt.isParamDependent =>
1892-
assert(mt.hasErasedParams)
1893-
RefinedType(defn.ErasedFunctionType, nme.apply, mt)
1894-
case poly @ PolyType(_, mt: MethodType) if !mt.isParamDependent =>
1878+
case mt: MethodType =>
1879+
assert(!mt.isParamDependent)
1880+
def nonDependentFunType =
1881+
val formals1 = if (dropLast == 0) mt.paramInfos else mt.paramInfos dropRight dropLast
1882+
val isContextual = mt.isContextualMethod && !ctx.erasedTypes
1883+
val result1 = mt.nonDependentResultApprox match {
1884+
case res: MethodType => res.toFunctionType(isJava)
1885+
case res => res
1886+
}
1887+
defn.FunctionOf(
1888+
formals1 mapConserve (_.translateFromRepeated(toArray = isJava)),
1889+
result1, isContextual)
1890+
if mt.hasErasedParams then
1891+
RefinedType(defn.ErasedFunctionType, nme.apply, mt)
1892+
else if alwaysDependent || mt.isResultDependent then
1893+
RefinedType(nonDependentFunType, nme.apply, mt)
1894+
else nonDependentFunType
1895+
case poly @ PolyType(_, mt: MethodType) =>
1896+
assert(!mt.isParamDependent)
18951897
RefinedType(defn.PolyFunctionType, nme.apply, poly)
18961898
}
18971899

0 commit comments

Comments
 (0)