Skip to content

Commit 0404238

Browse files
authored
Merge pull request #8245 from dotty-staging/i8188
Fix #8188: For the purposes of overloading, contextual methods aren't methodic
2 parents df0bb24 + 362bdca commit 0404238

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,7 @@ trait Applications extends Compatibility {
18241824
skip(alt.widen)
18251825

18261826
def resultIsMethod(tp: Type): Boolean = tp.widen.stripPoly match
1827-
case tp: MethodType => tp.resultType.isInstanceOf[MethodType]
1827+
case tp: MethodType => stripImplicit(tp.resultType).isInstanceOf[MethodType]
18281828
case _ => false
18291829

18301830
val found = narrowMostSpecific(candidates)

tests/pos/i2378.scala renamed to tests/neg/i2378.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class Test(val tb: Toolbox) {
2121
implicit val cap: Cap = null
2222

2323
def foo(tree: Tree): Int = (tree: Any) match {
24-
case tb.Apply(fun, args) => 3
24+
case tb.Apply(fun, args) => 3 // error: ambiguous overload of unapply
2525
}
2626

2727
def bar(tree: tpd.Tree): Int = (tree: Any) match {
28-
case Apply(fun, args) => 3
28+
case Apply(fun, args) => 3 // error: ambiguous overload of unapply
2929
}
3030
}

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(using DummyImplicit): String = ???
4+
def show(color: Boolean)(using 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)(using DummyImplicit): String = x * 2
3+
def f(x: String)(color: Boolean)(using 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)(using DummyImplicit): String = x * 2
3+
def f(x: String)(using DummyImplicit)(color: Boolean): String = x * 3
4+
}
5+
6+
@main def Test = println(new Foo().f("foo"))

0 commit comments

Comments
 (0)