Skip to content

Commit ad5b0ad

Browse files
Fix scala#8188: For the purposes of overloading, contextual methods aren't methodic
1 parent 76caf35 commit ad5b0ad

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
@@ -1315,6 +1315,16 @@ trait Applications extends Compatibility {
13151315
else if (sym1.is(Module)) compareOwner(sym1.companionClass, sym2)
13161316
else 0
13171317

1318+
/** Drop any implicit parameter section */
1319+
def stripImplicit(tp: Type)(using Context): Type = tp match {
1320+
case mt: MethodType if mt.isImplicitMethod =>
1321+
stripImplicit(resultTypeApprox(mt))
1322+
case pt: PolyType =>
1323+
pt.derivedLambdaType(pt.paramNames, pt.paramInfos, stripImplicit(pt.resultType))
1324+
case _ =>
1325+
tp
1326+
}
1327+
13181328
/** Compare to alternatives of an overloaded call or an implicit search.
13191329
*
13201330
* @param alt1, alt2 Non-overloaded references indicating the two choices
@@ -1466,16 +1476,6 @@ trait Applications extends Compatibility {
14661476
else tp
14671477
}
14681478

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-
14791479
def compareWithTypes(tp1: Type, tp2: Type) = {
14801480
val ownerScore = compareOwner(alt1.symbol.maybeOwner, alt2.symbol.maybeOwner)
14811481
def winsType1 = isAsSpecific(alt1, tp1, alt2, tp2)
@@ -1811,7 +1811,7 @@ trait Applications extends Compatibility {
18111811
}
18121812

18131813
def resultIsMethod(tp: Type): Boolean = tp.widen.stripPoly match
1814-
case tp: MethodType => tp.resultType.isInstanceOf[MethodType]
1814+
case tp: MethodType => stripImplicit(tp.resultType).isInstanceOf[MethodType]
18151815
case _ => false
18161816

18171817
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)