Skip to content

Commit db42419

Browse files
Fix #8188: For the purposes of overloading, contextual methods aren't methodic
1 parent 898d62b commit db42419

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,16 @@ trait Applications extends Compatibility {
12871287
else if (sym1.is(Module)) compareOwner(sym1.companionClass, sym2)
12881288
else 0
12891289

1290+
/** Drop any implicit parameter section */
1291+
def stripImplicit(tp: Type)(using Context): Type = tp match {
1292+
case mt: MethodType if mt.isImplicitMethod =>
1293+
stripImplicit(resultTypeApprox(mt))
1294+
case pt: PolyType =>
1295+
pt.derivedLambdaType(pt.paramNames, pt.paramInfos, stripImplicit(pt.resultType))
1296+
case _ =>
1297+
tp
1298+
}
1299+
12901300
/** Compare to alternatives of an overloaded call or an implicit search.
12911301
*
12921302
* @param alt1, alt2 Non-overloaded references indicating the two choices
@@ -1438,16 +1448,6 @@ trait Applications extends Compatibility {
14381448
else tp
14391449
}
14401450

1441-
/** Drop any implicit parameter section */
1442-
def stripImplicit(tp: Type): Type = tp match {
1443-
case mt: MethodType if mt.isImplicitMethod =>
1444-
stripImplicit(resultTypeApprox(mt))
1445-
case pt: PolyType =>
1446-
pt.derivedLambdaType(pt.paramNames, pt.paramInfos, stripImplicit(pt.resultType))
1447-
case _ =>
1448-
tp
1449-
}
1450-
14511451
def compareWithTypes(tp1: Type, tp2: Type) = {
14521452
val ownerScore = compareOwner(alt1.symbol.maybeOwner, alt2.symbol.maybeOwner)
14531453
def winsType1 = isAsSpecific(alt1, tp1, alt2, tp2)
@@ -1783,7 +1783,7 @@ trait Applications extends Compatibility {
17831783
}
17841784

17851785
def resultIsMethod(tp: Type): Boolean = tp.widen.stripPoly match
1786-
case tp: MethodType => tp.resultType.isInstanceOf[MethodType]
1786+
case tp: MethodType => stripImplicit(tp.resultType).isInstanceOf[MethodType]
17871787
case _ => false
17881788

17891789
val found = narrowMostSpecific(candidates)

tests/pos/i8188a.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object Test {
2+
extension StrDeco on (tree: String) {
3+
def show(given DummyImplicit): String = ???
4+
def show(color: Boolean)(given DummyImplicit): String = ???
5+
}
6+
7+
val a: String = "foo".show
8+
val b: String = "foo".show(true)
9+
val c: Any = "foo".show
10+
val d: Any = "foo".show(true)
11+
}

tests/pos/i8188b.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Foo {
2+
def f(x: String)(given DummyImplicit): String = x * 2
3+
def f(x: String)(color: Boolean)(given DummyImplicit): String = x * 3
4+
}
5+
6+
@main def Test = println(new Foo().f("foo"))

tests/pos/i8188c.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Foo {
2+
def f(x: String)(given DummyImplicit): String = x * 2
3+
def f(x: String)(given DummyImplicit)(color: Boolean): String = x * 3
4+
}
5+
6+
@main def Test = println(new Foo().f("foo"))

0 commit comments

Comments
 (0)