@@ -1897,13 +1897,19 @@ trait Applications extends Compatibility {
18971897 }
18981898
18991899 /** The type of alternative `alt` after instantiating its first parameter
1900- * clause with `argTypes`.
1900+ * clause with `argTypes`. In addition, if the resulting type is a PolyType
1901+ * and `typeArgs` matches its parameter list, instantiate the result with `typeArgs`.
19011902 */
1902- def skipParamClause (argTypes : List [Type ])(alt : TermRef ): Type =
1903+ def skipParamClause (argTypes : List [Type ], typeArgs : List [ Type ] )(alt : TermRef ): Type =
19031904 def skip (tp : Type ): Type = tp match {
19041905 case tp : PolyType =>
1905- val rt = skip(tp.resultType)
1906- if (rt.exists) tp.derivedLambdaType(resType = rt) else rt
1906+ skip(tp.resultType) match
1907+ case NoType =>
1908+ NoType
1909+ case rt : PolyType if typeArgs.length == rt.paramInfos.length =>
1910+ tp.derivedLambdaType(resType = rt.instantiate(typeArgs))
1911+ case rt =>
1912+ tp.derivedLambdaType(resType = rt).asInstanceOf [PolyType ].flatten
19071913 case tp : MethodType =>
19081914 tp.instantiate(argTypes)
19091915 case _ =>
@@ -1926,9 +1932,14 @@ trait Applications extends Compatibility {
19261932 else
19271933 val deepPt = pt.deepenProto
19281934 deepPt match
1935+ case pt @ FunProto (_, PolyProto (targs, resType)) =>
1936+ // try to narrow further with snd argument list and following type params
1937+ resolveMapped(candidates,
1938+ skipParamClause(pt.typedArgs().tpes, targs.tpes), resType)
19291939 case pt @ FunProto (_, resType : FunOrPolyProto ) =>
19301940 // try to narrow further with snd argument list
1931- resolveMapped(candidates, skipParamClause(pt.typedArgs().tpes), resType)
1941+ resolveMapped(candidates,
1942+ skipParamClause(pt.typedArgs().tpes, Nil ), resType)
19321943 case _ =>
19331944 // prefer alternatives that need no eta expansion
19341945 val noCurried = alts.filter(! resultIsMethod(_))
@@ -1974,7 +1985,7 @@ trait Applications extends Compatibility {
19741985 None
19751986 }
19761987 val mapped = reverseMapping.map(_._1)
1977- overload.println(i " resolve mapped: $mapped" )
1988+ overload.println(i " resolve mapped: ${ mapped.map(_.widen)} %, % with $pt " )
19781989 resolveOverloaded(mapped, pt).map(reverseMapping.toMap)
19791990
19801991 /** Try to typecheck any arguments in `pt` that are function values missing a
0 commit comments