File tree 2 files changed +13
-6
lines changed
compiler/src/dotty/tools/dotc
2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -1874,22 +1874,19 @@ object Types {
1874
1874
/** Turn type into a function type.
1875
1875
* @pre this is a method type without parameter dependencies.
1876
1876
* @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.
1879
1877
* @param alwaysDependent if true, always create a dependent function type.
1880
1878
*/
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 {
1882
1880
case mt : MethodType =>
1883
1881
assert(! mt.isParamDependent)
1884
1882
def nonDependentFunType =
1885
- val formals1 = if (dropLast == 0 ) mt.paramInfos else mt.paramInfos dropRight dropLast
1886
1883
val isContextual = mt.isContextualMethod && ! ctx.erasedTypes
1887
1884
val result1 = mt.nonDependentResultApprox match {
1888
1885
case res : MethodType => res.toFunctionType(isJava)
1889
1886
case res => res
1890
1887
}
1891
1888
defn.FunctionOf (
1892
- formals1 mapConserve (_.translateFromRepeated(toArray = isJava)),
1889
+ mt.paramInfos. mapConserve(_.translateFromRepeated(toArray = isJava)),
1893
1890
result1, isContextual)
1894
1891
if mt.hasErasedParams then
1895
1892
defn.PolyFunctionOf (mt)
Original file line number Diff line number Diff line change @@ -405,7 +405,17 @@ trait TypeAssigner {
405
405
406
406
def assignType (tree : untpd.Closure , meth : Tree , target : Tree )(using Context ): Closure =
407
407
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 ))
409
419
else target.tpe)
410
420
411
421
def assignType (tree : untpd.CaseDef , pat : Tree , body : Tree )(using Context ): CaseDef = {
You can’t perform that action at this time.
0 commit comments