Skip to content

Commit 6fe5f8e

Browse files
authored
Merge pull request #11369 from dotty-staging/fix-11358
Merge multiple parameter lists in resolveOverloaded
2 parents 9834cae + c812c5d commit 6fe5f8e

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

tests/pos/i11358.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object Test:
2+
3+
def test1: IArray[Int] = IArray(1, 2) +++ IArray(2, 3)
4+
def test2: IArray[Int] = IArray(1, 2) +++ List(2, 3)
5+
def test3 = +++[Int](IArray(1, 2))(IArray(2, 3))
6+
def test4 = +++[Int](IArray(1, 2))(List(2, 3))
7+
def test5: IArray[Int] = IArray(1, 2).+++[Int](IArray(2, 3))
8+
def test6: IArray[Int] = IArray(1, 2).+++[Int](List(2, 3))
9+
def test7 = +++(IArray(1, 2))[Int](IArray(2, 3))
10+
def test8 = +++(IArray(1, 2))[Int](List(2, 3))
11+
12+
extension [A: reflect.ClassTag](arr: IArray[A])
13+
def +++[B >: A: reflect.ClassTag](suffix: IArray[B]): IArray[B] = ???
14+
def +++[B >: A: reflect.ClassTag](suffix: IterableOnce[B]): IArray[B] = ???

0 commit comments

Comments
 (0)