File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -1858,20 +1858,18 @@ object Types {
18581858
18591859 /** Turn type into a function type.
18601860 * @pre this is a method type without parameter dependencies.
1861- * @param dropLast the number of trailing parameters that should be dropped
1862- * when forming the function type.
1861+ * @param isJava translate repeated params as as java `Array`s?
18631862 * @param alwaysDependent if true, always create a dependent function type.
18641863 */
18651864 def toFunctionType (isJava : Boolean = false , dropLast : Int = 0 , alwaysDependent : Boolean = false )(using Context ): Type = this match {
18661865 case mt : MethodType if ! mt.isParamDependent && ! mt.hasErasedParams =>
1867- val formals1 = if (dropLast == 0 ) mt.paramInfos else mt.paramInfos dropRight dropLast
18681866 val isContextual = mt.isContextualMethod && ! ctx.erasedTypes
18691867 val result1 = mt.nonDependentResultApprox match {
18701868 case res : MethodType => res.toFunctionType(isJava)
18711869 case res => res
18721870 }
18731871 val funType = defn.FunctionOf (
1874- formals1 mapConserve (_.translateFromRepeated(toArray = isJava)),
1872+ mt.paramInfos. mapConserve(_.translateFromRepeated(toArray = isJava)),
18751873 result1, isContextual)
18761874 if alwaysDependent || mt.isResultDependent then
18771875 RefinedType (funType, nme.apply, mt)
Original file line number Diff line number Diff 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 = {
You can’t perform that action at this time.
0 commit comments