File tree 2 files changed +13
-5
lines changed
compiler/src/dotty/tools/dotc
2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -1858,20 +1858,18 @@ object Types {
1858
1858
1859
1859
/** Turn type into a function type.
1860
1860
* @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?
1863
1862
* @param alwaysDependent if true, always create a dependent function type.
1864
1863
*/
1865
1864
def toFunctionType (isJava : Boolean = false , dropLast : Int = 0 , alwaysDependent : Boolean = false )(using Context ): Type = this match {
1866
1865
case mt : MethodType if ! mt.isParamDependent && ! mt.hasErasedParams =>
1867
- val formals1 = if (dropLast == 0 ) mt.paramInfos else mt.paramInfos dropRight dropLast
1868
1866
val isContextual = mt.isContextualMethod && ! ctx.erasedTypes
1869
1867
val result1 = mt.nonDependentResultApprox match {
1870
1868
case res : MethodType => res.toFunctionType(isJava)
1871
1869
case res => res
1872
1870
}
1873
1871
val funType = defn.FunctionOf (
1874
- formals1 mapConserve (_.translateFromRepeated(toArray = isJava)),
1872
+ mt.paramInfos. mapConserve(_.translateFromRepeated(toArray = isJava)),
1875
1873
result1, isContextual)
1876
1874
if alwaysDependent || mt.isResultDependent then
1877
1875
RefinedType (funType, nme.apply, mt)
Original file line number Diff line number Diff line change @@ -401,7 +401,17 @@ trait TypeAssigner {
401
401
402
402
def assignType (tree : untpd.Closure , meth : Tree , target : Tree )(using Context ): Closure =
403
403
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 ))
405
415
else target.tpe)
406
416
407
417
def assignType (tree : untpd.CaseDef , pat : Tree , body : Tree )(using Context ): CaseDef = {
You can’t perform that action at this time.
0 commit comments