Skip to content

Commit

Permalink
Reproduce and fix error that affected findRef
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Jul 15, 2023
1 parent 1892d65 commit 463ee8c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
10 changes: 6 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,13 @@ object Implicits:
def filter(xs: List[Candidate], remove: List[Candidate]) =
val shadowed = remove.map(_.ref.implicitName).toSet
xs.filterConserve(cand => !shadowed.contains(cand.ref.implicitName))

val outer = outerImplicits.uncheckedNN
def isWildcardImport(using Context) = ctx.importInfo.nn.isWildcardImport
if (irefCtx.scope eq irefCtx.outer.scope) && (
isImport && !outerImplicits.nn.isImport
|| isWildcardImport && !isWildcardImport(using outerImplicits.nn.irefCtx)
) then
def preferDefinitions = isImport && !outer.isImport
def preferNamedImport = isWildcardImport && !isWildcardImport(using outer.irefCtx)

if level == outer.level && (preferDefinitions || preferNamedImport) then
// special cases: definitions beat imports, and named imports beat
// wildcard imports, provided both are in contexts with same scope
filter(ownEligible, outerEligible) ::: outerEligible
Expand Down
17 changes: 17 additions & 0 deletions tests/run/i18183.findRef.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// A minimised reproduction of how an initial change to combineEligibles broke Typer#findRef
case class Foo(n: Int)

class Test:
import this.toString

val foo1 = Foo(1)
val foo2 = Foo(2)

def foo(using Foo): Foo =
import this.*
def bar(using Foo): Foo = summon[Foo]
bar(using foo2)

object Test extends Test:
def main(args: Array[String]): Unit =
assert(foo(using foo1) eq foo2)

0 comments on commit 463ee8c

Please sign in to comment.