@@ -1299,6 +1299,16 @@ trait Applications extends Compatibility {
1299
1299
}
1300
1300
}
1301
1301
1302
+ /** Drop any implicit parameter section */
1303
+ def stripImplicit (tp : Type )(using Context ): Type = tp match {
1304
+ case mt : MethodType if mt.isImplicitMethod =>
1305
+ stripImplicit(resultTypeApprox(mt))
1306
+ case pt : PolyType =>
1307
+ pt.derivedLambdaType(pt.paramNames, pt.paramInfos, stripImplicit(pt.resultType))
1308
+ case _ =>
1309
+ tp
1310
+ }
1311
+
1302
1312
/** Compare owner inheritance level.
1303
1313
* @param sym1 The first owner
1304
1314
* @param sym2 The second owner
@@ -1466,16 +1476,6 @@ trait Applications extends Compatibility {
1466
1476
else tp
1467
1477
}
1468
1478
1469
- /** Drop any implicit parameter section */
1470
- def stripImplicit (tp : Type ): Type = tp match {
1471
- case mt : MethodType if mt.isImplicitMethod =>
1472
- stripImplicit(resultTypeApprox(mt))
1473
- case pt : PolyType =>
1474
- pt.derivedLambdaType(pt.paramNames, pt.paramInfos, stripImplicit(pt.resultType))
1475
- case _ =>
1476
- tp
1477
- }
1478
-
1479
1479
def compareWithTypes (tp1 : Type , tp2 : Type ) = {
1480
1480
val ownerScore = compareOwner(alt1.symbol.maybeOwner, alt2.symbol.maybeOwner)
1481
1481
def winsType1 = isAsSpecific(alt1, tp1, alt2, tp2)
@@ -1707,6 +1707,22 @@ trait Applications extends Compatibility {
1707
1707
case _ => arg
1708
1708
end normArg
1709
1709
1710
+ /** Resolve overloading by mapping to a different problem where each alternative's
1711
+ * type is mapped with `f`, alternatives with non-existing types are dropped, and the
1712
+ * expected type is `pt`. Map the results back to the original alternatives.
1713
+ */
1714
+ def resolveMapped (alts : List [TermRef ], f : TermRef => Type , pt : Type ): List [TermRef ] =
1715
+ val reverseMapping = alts.flatMap { alt =>
1716
+ val t = f(alt)
1717
+ if t.exists then
1718
+ Some ((TermRef (NoPrefix , alt.symbol.asTerm.copy(info = t)), alt))
1719
+ else
1720
+ None
1721
+ }
1722
+ val mapped = reverseMapping.map(_._1)
1723
+ overload.println(i " resolve mapped: $mapped" )
1724
+ resolveOverloaded(mapped, pt, targs).map(reverseMapping.toMap)
1725
+
1710
1726
val candidates = pt match {
1711
1727
case pt @ FunProto (args, resultType) =>
1712
1728
val numArgs = args.length
@@ -1747,6 +1763,15 @@ trait Applications extends Compatibility {
1747
1763
alts2
1748
1764
}
1749
1765
1766
+ if pt.isGivenApply then
1767
+ val alts0 = alts.filterConserve { alt =>
1768
+ val mt = alt.widen.stripPoly
1769
+ mt.isImplicitMethod || mt.isContextualMethod
1770
+ }
1771
+ if alts0 ne alts then return resolveOverloaded(alts0, pt, targs)
1772
+ else if alts.exists(_.widen.stripPoly.isContextualMethod) then
1773
+ return resolveMapped(alts, alt => stripImplicit(alt.widen), pt)
1774
+
1750
1775
val alts1 = narrowBySize(alts)
1751
1776
// ctx.log(i"narrowed by size: ${alts1.map(_.symbol.showDcl)}%, %")
1752
1777
if isDetermined(alts1) then alts1
@@ -1783,34 +1808,19 @@ trait Applications extends Compatibility {
1783
1808
else compat
1784
1809
}
1785
1810
1786
- /** Resolve overloading by mapping to a different problem where each alternative's
1787
- * type is mapped with `f`, alternatives with non-existing types are dropped, and the
1788
- * expected type is `pt`. Map the results back to the original alternatives.
1789
- */
1790
- def resolveMapped (alts : List [TermRef ], f : TermRef => Type , pt : Type ): List [TermRef ] =
1791
- val reverseMapping = alts.flatMap { alt =>
1792
- val t = f(alt)
1793
- if t.exists then
1794
- Some ((TermRef (NoPrefix , alt.symbol.asTerm.copy(info = t)), alt))
1795
- else
1796
- None
1797
- }
1798
- val mapped = reverseMapping.map(_._1)
1799
- overload.println(i " resolve mapped: $mapped" )
1800
- resolveOverloaded(mapped, pt, targs).map(reverseMapping.toMap)
1801
-
1802
1811
/** The type of alternative `alt` after instantiating its first parameter
1803
1812
* clause with `argTypes`.
1804
1813
*/
1805
1814
def skipParamClause (argTypes : List [Type ])(alt : TermRef ): Type =
1806
- def skip (tp : Type ): Type = tp match
1815
+ def skip (tp : Type ): Type = tp match {
1807
1816
case tp : PolyType =>
1808
1817
val rt = skip(tp.resultType)
1809
- if rt.exists then tp.derivedLambdaType(resType = rt) else rt
1818
+ if ( rt.exists) tp.derivedLambdaType(resType = rt) else rt
1810
1819
case tp : MethodType =>
1811
1820
tp.instantiate(argTypes)
1812
1821
case _ =>
1813
1822
NoType
1823
+ }
1814
1824
skip(alt.widen)
1815
1825
1816
1826
def resultIsMethod (tp : Type ): Boolean = tp.widen.stripPoly match
0 commit comments