Skip to content

Commit 7dab752

Browse files
committed
Avoid spurious shadowing errors
If `x` had implicit function type, the previous algorithm did not realize that `x` and `x.apply(y)` were the same reference. Therefore, a spurious shadowing error occurred and the implicit search failed.
1 parent cf44c8a commit 7dab752

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -752,10 +752,12 @@ trait Implicits { self: Typer =>
752752
lazy val shadowing =
753753
typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto)(
754754
nestedContext.addMode(Mode.ImplicitShadowing).setExploreTyperState)
755-
def refMatches(shadowing: Tree): Boolean =
755+
def refSameAs(shadowing: Tree): Boolean =
756756
ref.symbol == closureBody(shadowing).symbol || {
757757
shadowing match {
758-
case Trees.Select(qual, nme.apply) => refMatches(qual)
758+
case Trees.Select(qual, nme.apply) => refSameAs(qual)
759+
case Trees.Apply(fn, _) => refSameAs(fn)
760+
case Trees.TypeApply(fn, _) => refSameAs(fn)
759761
case _ => false
760762
}
761763
}
@@ -782,7 +784,7 @@ trait Implicits { self: Typer =>
782784
if (ctx.reporter.hasErrors)
783785
nonMatchingImplicit(ref, ctx.reporter.removeBufferedMessages)
784786
else if (contextual && !ctx.mode.is(Mode.ImplicitShadowing) &&
785-
!shadowing.tpe.isError && !refMatches(shadowing)) {
787+
!shadowing.tpe.isError && !refSameAs(shadowing)) {
786788
implicits.println(i"SHADOWING $ref in ${ref.termSymbol.owner} is shadowed by $shadowing in ${shadowing.symbol.owner}")
787789
shadowedImplicit(ref, methPart(shadowing).tpe)
788790
}

0 commit comments

Comments
 (0)