Skip to content

Commit 3419d8a

Browse files
committed
Remove dropLast from toFunctionType
If needed, use `derivedLambdaType` to drop the last parameters before converting to a function type.
1 parent eb8fba4 commit 3419d8a

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
@@ -1874,22 +1874,19 @@ object Types {
18741874
/** Turn type into a function type.
18751875
* @pre this is a method type without parameter dependencies.
18761876
* @param isJava translate repeated params as as java `Array`s?
1877-
* @param dropLast the number of trailing parameters that should be dropped
1878-
* when forming the function type.
18791877
* @param alwaysDependent if true, always create a dependent function type.
18801878
*/
1881-
def toFunctionType(isJava: Boolean = false, dropLast: Int = 0, alwaysDependent: Boolean = false)(using Context): Type = this match {
1879+
def toFunctionType(isJava: Boolean = false, alwaysDependent: Boolean = false)(using Context): Type = this match {
18821880
case mt: MethodType =>
18831881
assert(!mt.isParamDependent)
18841882
def nonDependentFunType =
1885-
val formals1 = if (dropLast == 0) mt.paramInfos else mt.paramInfos dropRight dropLast
18861883
val isContextual = mt.isContextualMethod && !ctx.erasedTypes
18871884
val result1 = mt.nonDependentResultApprox match {
18881885
case res: MethodType => res.toFunctionType(isJava)
18891886
case res => res
18901887
}
18911888
defn.FunctionOf(
1892-
formals1 mapConserve (_.translateFromRepeated(toArray = isJava)),
1889+
mt.paramInfos.mapConserve(_.translateFromRepeated(toArray = isJava)),
18931890
result1, isContextual)
18941891
if mt.hasErasedParams then
18951892
defn.PolyFunctionOf(mt)

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

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

406406
def assignType(tree: untpd.Closure, meth: Tree, target: Tree)(using Context): Closure =
407407
tree.withType(
408-
if (target.isEmpty) meth.tpe.widen.toFunctionType(isJava = meth.symbol.is(JavaDefined), tree.env.length)
408+
if target.isEmpty then
409+
def methTypeWithoutEnv(info: Type): Type = info match
410+
case mt: MethodType =>
411+
val dropLast = tree.env.length
412+
val paramNames = mt.paramNames.dropRight(dropLast)
413+
val paramInfos = mt.paramInfos.dropRight(dropLast)
414+
mt.derivedLambdaType(paramNames, paramInfos)
415+
case pt: PolyType =>
416+
pt.derivedLambdaType(resType = methTypeWithoutEnv(pt.resType))
417+
val methodicType = if tree.env.isEmpty then meth.tpe.widen else methTypeWithoutEnv(meth.tpe.widen)
418+
methodicType.toFunctionType(isJava = meth.symbol.is(JavaDefined))
409419
else target.tpe)
410420

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

0 commit comments

Comments
 (0)