Skip to content

Commit e78fc93

Browse files
committed
Drop implicit shadowing checks
Since implicit selection is now inner to outer, shadowing checks are less important than before. Shadowing is necessary if we treat implicit search as a synthesis for untyped terms. I.e. come up with an untyped term and then check whether that term is typeable and refers to the original implicit. If there's a nested definition with the same name, that fails. This viewpoint is very easy to spec but a bit unnatural. In all other instances of meta programming we deal with typed terms. If we synthesize a typed term directly, then name resolution is already done and shadowing is immaterial. Besides, shadowing tests, if they fail, are almost always much more suprising than enlightening.
1 parent 1019f77 commit e78fc93

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,8 @@ trait Implicits { self: Typer =>
11051105
}
11061106
}
11071107
}
1108-
else if (contextual && !ctx.mode.is(Mode.ImplicitShadowing) &&
1108+
else if (false &&
1109+
contextual && !ctx.mode.is(Mode.ImplicitShadowing) &&
11091110
!shadowing.tpe.isError && !refSameAs(shadowing)) {
11101111
implicits.println(i"SHADOWING $ref in ${ref.termSymbol.maybeOwner} is shadowed by $shadowing in ${shadowing.symbol.maybeOwner}")
11111112
SearchFailure(generated1.withTypeUnchecked(

tests/neg/implicit-shadowing.scala renamed to tests/pos/implicit-shadowing.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ object Test {
44

55
def outer(implicit c: C) = {
66

7-
def f(c: C) = implicitly[C] // error: shadowing
8-
def g(c: Int) = implicitly[C] // error: shadowing (even though type is different)
7+
def f(c: C) = implicitly[C] // now ok: shadowing no longer tested
8+
def g(c: Int) = implicitly[C] // now ok: shadowing no longer tested
99

1010
f(new C)
1111
}

tests/run/i5224.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
barInt
2-
bar
2+
barInt

tests/run/i5224.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ object Test extends App {
1616
def barInt: Unit = ???
1717

1818
implicitly[Bar[Int]]
19+
// used to resolve to bar, but
20+
// resolves to barInt now, since shadowing is no longer tested
1921
}
2022
}

0 commit comments

Comments
 (0)