Skip to content

Commit 49af4fb

Browse files
committed
Merge nested polytypes in more cases in resolveOverloaded
In some cases while going deeper into alternatives during overload resolution, we may end up with a nested polytype after dropping contextual parameters. In particular this can happen for an extension with a `using` clause, as seen in tests/pos/i11713.scala and tests/pos/i13668.scala. The overload applicability test fails here unless the type parameter lists are merged. Co-authored-by: Gagandeep Kalra <[email protected]> Co-authored-by: Mark T. Kennedy <[email protected]> Fixes #11713 Fixes #13668
1 parent b184009 commit 49af4fb

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,7 @@ trait Applications extends Compatibility {
14661466
case mt: MethodType if mt.isImplicitMethod =>
14671467
stripImplicit(resultTypeApprox(mt))
14681468
case pt: PolyType =>
1469-
pt.derivedLambdaType(pt.paramNames, pt.paramInfos, stripImplicit(pt.resultType))
1469+
pt.derivedLambdaType(pt.paramNames, pt.paramInfos, stripImplicit(pt.resultType)).asInstanceOf[PolyType].flatten
14701470
case _ =>
14711471
tp
14721472
}
@@ -1520,7 +1520,7 @@ trait Applications extends Compatibility {
15201520
else compareOwner(cls1, sym2)
15211521
else 0
15221522

1523-
/** Compare to alternatives of an overloaded call or an implicit search.
1523+
/** Compare two alternatives of an overloaded call or an implicit search.
15241524
*
15251525
* @param alt1, alt2 Non-overloaded references indicating the two choices
15261526
* @return 1 if 1st alternative is preferred over 2nd

tests/pos/i11713.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extension [T1](x: T1)(using Numeric[T1])
2+
def combine[T2](y: T2)(using Numeric[T2]) = ???
3+
def combine(y: String) = ???
4+
5+
val res = 100.combine(200)

tests/pos/i13668.scala

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class MyType()
2+
trait Candidate[R]
3+
given Candidate[MyType] with {}
4+
class Fuzzy[W]()
5+
class Fuzzy1()
6+
class Bear()
7+
8+
extension [L](lhs: L)(using Candidate[L])
9+
def +[RW](rhs: Fuzzy[RW]): Unit = {}
10+
def +(rhs: Bear): Unit = {}
11+
def -(rhs: Fuzzy1): Unit = {}
12+
def -(rhs: Bear): Unit = {}
13+
14+
val works = MyType() - Fuzzy1()
15+
val fails = MyType() + Fuzzy[1]()

0 commit comments

Comments
 (0)