Skip to content

Commit aef96f6

Browse files
committed
Support all combinations of explicit type parameters
Support all combinations of explicit vs inferred type parameters in overloaded variants with multiple type parameter lists.
1 parent 0732386 commit aef96f6

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,11 +1899,16 @@ trait Applications extends Compatibility {
18991899
/** The type of alternative `alt` after instantiating its first parameter
19001900
* clause with `argTypes`.
19011901
*/
1902-
def skipParamClause(argTypes: List[Type])(alt: TermRef): Type =
1902+
def skipParamClause(argTypes: List[Type], typeArgs: List[Type])(alt: TermRef): Type =
19031903
def skip(tp: Type): Type = tp match {
19041904
case tp: PolyType =>
1905-
val rt = skip(tp.resultType)
1906-
if rt.exists then tp.derivedLambdaType(resType = rt).asInstanceOf[PolyType].flatten else rt
1905+
skip(tp.resultType) match
1906+
case NoType =>
1907+
NoType
1908+
case rt: PolyType if typeArgs.length == rt.paramInfos.length =>
1909+
tp.derivedLambdaType(resType = rt.instantiate(typeArgs))
1910+
case rt =>
1911+
tp.derivedLambdaType(resType = rt).asInstanceOf[PolyType].flatten
19071912
case tp: MethodType =>
19081913
tp.instantiate(argTypes)
19091914
case _ =>
@@ -1926,9 +1931,14 @@ trait Applications extends Compatibility {
19261931
else
19271932
val deepPt = pt.deepenProto
19281933
deepPt match
1934+
case pt @ FunProto(_, PolyProto(targs, resType)) =>
1935+
// try to narrow further with snd argument list and following type params
1936+
resolveMapped(candidates,
1937+
skipParamClause(pt.typedArgs().tpes, targs.tpes), resType)
19291938
case pt @ FunProto(_, resType: FunOrPolyProto) =>
19301939
// try to narrow further with snd argument list
1931-
resolveMapped(candidates, skipParamClause(pt.typedArgs().tpes), resType)
1940+
resolveMapped(candidates,
1941+
skipParamClause(pt.typedArgs().tpes, Nil), resType)
19321942
case _ =>
19331943
// prefer alternatives that need no eta expansion
19341944
val noCurried = alts.filter(!resultIsMethod(_))

tests/pos/i11358.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ object Test:
22

33
def test1: IArray[Int] = IArray(1, 2) +++ IArray(2, 3)
44
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))
511

612
extension [A: reflect.ClassTag](arr: IArray[A])
713
def +++[B >: A: reflect.ClassTag](suffix: IArray[B]): IArray[B] = ???

0 commit comments

Comments
 (0)