Skip to content

Commit 3c91726

Browse files
Fix #6816: Deny methods with implicit members from tpd.applyOverloaded
We cannot resolve implicit parameters outside Typer. Hence methods that require implicit parameters should not be considered.
1 parent eb12c21 commit 3c91726

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,9 +1146,14 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
11461146
case tp: PolyType => tp.paramInfos.length
11471147
case _ => 0
11481148
}
1149+
11491150
var allAlts = denot.alternatives
11501151
.map(denot => TermRef(receiver.tpe, denot.symbol))
11511152
.filter(tr => typeParamCount(tr) == targs.length)
1153+
.filter { _.widen match {
1154+
case MethodTpe(_, _, x: MethodType) => !x.isImplicitMethod
1155+
case _ => true
1156+
}}
11521157
if (targs.isEmpty) allAlts = allAlts.filterNot(_.widen.isInstanceOf[PolyType])
11531158
val alternatives = ctx.typer.resolveOverloaded(allAlts, proto)
11541159
assert(alternatives.size == 1,

tests/run/i6816.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
trait Bar
2+
trait Foo {
3+
def ==(that: Foo)(implicit b: Bar): Boolean = ???
4+
}
5+
6+
case class FooCC(f: Foo)
7+
8+
object Test {
9+
def main(args: Array[String]): Unit = {
10+
val foo1, foo2 = new Foo {}
11+
assert(FooCC(foo1) == FooCC(foo1))
12+
assert(FooCC(foo1) != FooCC(foo2))
13+
}
14+
}

0 commit comments

Comments
 (0)