Skip to content

Commit 463ee8c

Browse files
committed
Reproduce and fix error that affected findRef
1 parent 1892d65 commit 463ee8c

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,13 @@ object Implicits:
333333
def filter(xs: List[Candidate], remove: List[Candidate]) =
334334
val shadowed = remove.map(_.ref.implicitName).toSet
335335
xs.filterConserve(cand => !shadowed.contains(cand.ref.implicitName))
336+
337+
val outer = outerImplicits.uncheckedNN
336338
def isWildcardImport(using Context) = ctx.importInfo.nn.isWildcardImport
337-
if (irefCtx.scope eq irefCtx.outer.scope) && (
338-
isImport && !outerImplicits.nn.isImport
339-
|| isWildcardImport && !isWildcardImport(using outerImplicits.nn.irefCtx)
340-
) then
339+
def preferDefinitions = isImport && !outer.isImport
340+
def preferNamedImport = isWildcardImport && !isWildcardImport(using outer.irefCtx)
341+
342+
if level == outer.level && (preferDefinitions || preferNamedImport) then
341343
// special cases: definitions beat imports, and named imports beat
342344
// wildcard imports, provided both are in contexts with same scope
343345
filter(ownEligible, outerEligible) ::: outerEligible

tests/run/i18183.findRef.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// A minimised reproduction of how an initial change to combineEligibles broke Typer#findRef
2+
case class Foo(n: Int)
3+
4+
class Test:
5+
import this.toString
6+
7+
val foo1 = Foo(1)
8+
val foo2 = Foo(2)
9+
10+
def foo(using Foo): Foo =
11+
import this.*
12+
def bar(using Foo): Foo = summon[Foo]
13+
bar(using foo2)
14+
15+
object Test extends Test:
16+
def main(args: Array[String]): Unit =
17+
assert(foo(using foo1) eq foo2)

0 commit comments

Comments
 (0)