Skip to content

Commit f8c6b90

Browse files
committed
Remove dropLast from toFunctionType
If needed, use `derivedLambdaType` to drop the last parameters before converting to a function type. [Cherry-picked 3419d8a][modified]
1 parent a59a626 commit f8c6b90

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,20 +1859,17 @@ object Types {
18591859
/** Turn type into a function type.
18601860
* @pre this is a method type without parameter dependencies.
18611861
* @param isJava translate repeated params as as java `Array`s?
1862-
* @param dropLast the number of trailing parameters that should be dropped
1863-
* when forming the function type.
18641862
* @param alwaysDependent if true, always create a dependent function type.
18651863
*/
1866-
def toFunctionType(isJava: Boolean = false, dropLast: Int = 0, alwaysDependent: Boolean = false)(using Context): Type = this match {
1864+
def toFunctionType(isJava: Boolean = false, alwaysDependent: Boolean = false)(using Context): Type = this match {
18671865
case mt: MethodType if !mt.isParamDependent && !mt.hasErasedParams =>
1868-
val formals1 = if (dropLast == 0) mt.paramInfos else mt.paramInfos dropRight dropLast
18691866
val isContextual = mt.isContextualMethod && !ctx.erasedTypes
18701867
val result1 = mt.nonDependentResultApprox match {
18711868
case res: MethodType => res.toFunctionType(isJava)
18721869
case res => res
18731870
}
18741871
val funType = defn.FunctionOf(
1875-
formals1 mapConserve (_.translateFromRepeated(toArray = isJava)),
1872+
mt.paramInfos.mapConserve(_.translateFromRepeated(toArray = isJava)),
18761873
result1, isContextual)
18771874
if alwaysDependent || mt.isResultDependent then
18781875
RefinedType(funType, nme.apply, mt)

compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,17 @@ trait TypeAssigner {
401401

402402
def assignType(tree: untpd.Closure, meth: Tree, target: Tree)(using Context): Closure =
403403
tree.withType(
404-
if (target.isEmpty) meth.tpe.widen.toFunctionType(isJava = meth.symbol.is(JavaDefined), tree.env.length)
404+
if target.isEmpty then
405+
def methTypeWithoutEnv(info: Type): Type = info match
406+
case mt: MethodType =>
407+
val dropLast = tree.env.length
408+
val paramNames = mt.paramNames.dropRight(dropLast)
409+
val paramInfos = mt.paramInfos.dropRight(dropLast)
410+
mt.derivedLambdaType(paramNames, paramInfos)
411+
case pt: PolyType =>
412+
pt.derivedLambdaType(resType = methTypeWithoutEnv(pt.resType))
413+
val methodicType = if tree.env.isEmpty then meth.tpe.widen else methTypeWithoutEnv(meth.tpe.widen)
414+
methodicType.toFunctionType(isJava = meth.symbol.is(JavaDefined))
405415
else target.tpe)
406416

407417
def assignType(tree: untpd.CaseDef, pat: Tree, body: Tree)(using Context): CaseDef = {

0 commit comments

Comments
 (0)