Skip to content

Commit 123bd1e

Browse files
committed
Drop logic for shadowed implicits checking
1 parent 25c2bf1 commit 123bd1e

File tree

2 files changed

+10
-60
lines changed

2 files changed

+10
-60
lines changed

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,6 @@ class PlainPrinter(_ctx: Context) extends Printer {
520520
result.reason match {
521521
case _: NoMatchingImplicits => "No Matching Implicit"
522522
case _: DivergingImplicit => "Diverging Implicit"
523-
case _: ShadowedImplicit => "Shadowed Implicit"
524523
case result: AmbiguousImplicits =>
525524
"Ambiguous Implicit: " ~ toText(result.alt1.ref) ~ " and " ~ toText(result.alt2.ref)
526525
case _ =>

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

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -437,20 +437,6 @@ object Implicits {
437437
em"${err.refStr(ref)} does not $qualify"
438438
}
439439

440-
class ShadowedImplicit(ref: TermRef,
441-
shadowing: Type,
442-
val expectedType: Type,
443-
val argument: Tree) extends SearchFailureType {
444-
/** same as err.refStr but always prints owner even if it is a term */
445-
def show(ref: Type)(implicit ctx: Context): String = ref match {
446-
case ref: NamedType if ref.symbol.maybeOwner.isTerm =>
447-
i"${ref.symbol} in ${ref.symbol.owner}"
448-
case _ => err.refStr(ref)
449-
}
450-
def explanation(implicit ctx: Context): String =
451-
em"${show(ref)} does $qualify but it is shadowed by ${show(shadowing)}"
452-
}
453-
454440
class DivergingImplicit(ref: TermRef,
455441
val expectedType: Type,
456442
val argument: Tree) extends SearchFailureType {
@@ -795,9 +781,6 @@ trait Implicits { self: Typer =>
795781
shortForm
796782
case _ =>
797783
arg.tpe match {
798-
case tpe: ShadowedImplicit =>
799-
i"""$headline;
800-
|${tpe.explanation}."""
801784
case tpe: SearchFailureType =>
802785
i"""$headline.
803786
|I found:
@@ -1000,9 +983,9 @@ trait Implicits { self: Typer =>
1000983
/** Try to typecheck an implicit reference */
1001984
def typedImplicit(cand: Candidate, contextual: Boolean)(implicit ctx: Context): SearchResult = track("typedImplicit") { trace(i"typed implicit ${cand.ref}, pt = $pt, implicitsEnabled == ${ctx.mode is ImplicitsEnabled}", implicits, show = true) {
1002985
val ref = cand.ref
1003-
var generated: Tree = tpd.ref(ref).withSpan(span.startPos)
986+
val generated: Tree = tpd.ref(ref).withSpan(span.startPos)
1004987
val locked = ctx.typerState.ownedVars
1005-
val generated1 =
988+
val adapted =
1006989
if (argument.isEmpty)
1007990
adapt(generated, pt, locked)
1008991
else {
@@ -1024,52 +1007,20 @@ trait Implicits { self: Typer =>
10241007
}
10251008
else tryConversion
10261009
}
1027-
lazy val shadowing =
1028-
typedUnadapted(untpd.Ident(cand.implicitRef.implicitName).withSpan(span.toSynthetic))(
1029-
nestedContext().addMode(Mode.ImplicitShadowing).setExploreTyperState())
1030-
1031-
/** Is candidate reference the same as the `shadowing` reference? (i.e.
1032-
* no actual shadowing occured). This is the case if the
1033-
* underlying symbol of the shadowing reference is the same as the
1034-
* symbol of the candidate reference, or if they have a common type owner.
1035-
*
1036-
* The second condition (same owner) is needed because the candidate reference
1037-
* and the potential shadowing reference are typechecked with different prototypes.
1038-
* so might yield different overloaded symbols. E.g. if the candidate reference
1039-
* is to an implicit conversion generated from an implicit class, the shadowing
1040-
* reference could go to the companion object of that class instead.
1041-
*/
1042-
def refSameAs(shadowing: Tree): Boolean = {
1043-
def symMatches(sym: Symbol): Boolean =
1044-
sym == ref.symbol || sym.owner.isType && sym.owner == ref.symbol.owner
1045-
def denotMatches(d: Denotation): Boolean = d match {
1046-
case d: SingleDenotation => symMatches(d.symbol)
1047-
case d => d.hasAltWith(denotMatches(_))
1048-
}
1049-
denotMatches(closureBody(shadowing).denot)
1050-
}
1051-
10521010
if (ctx.reporter.hasErrors) {
10531011
ctx.reporter.removeBufferedMessages
10541012
SearchFailure {
1055-
generated1.tpe match {
1056-
case _: SearchFailureType => generated1
1057-
case _ => generated1.withType(new MismatchedImplicit(ref, pt, argument))
1013+
adapted.tpe match {
1014+
case _: SearchFailureType => adapted
1015+
case _ => adapted.withType(new MismatchedImplicit(ref, pt, argument))
10581016
}
10591017
}
10601018
}
1061-
else if (false &&
1062-
contextual && !ctx.mode.is(Mode.ImplicitShadowing) &&
1063-
!shadowing.tpe.isError && !refSameAs(shadowing)) {
1064-
implicits.println(i"SHADOWING $ref in ${ref.termSymbol.maybeOwner} is shadowed by $shadowing in ${shadowing.symbol.maybeOwner}")
1065-
SearchFailure(generated1.withTypeUnchecked(
1066-
new ShadowedImplicit(ref, methPart(shadowing).tpe, pt, argument)))
1067-
}
10681019
else {
1069-
val generated2 =
1070-
if (cand.isExtension) Applications.ExtMethodApply(generated1).withType(generated1.tpe)
1071-
else generated1
1072-
SearchSuccess(generated2, ref, cand.level)(ctx.typerState, ctx.gadt)
1020+
val returned =
1021+
if (cand.isExtension) Applications.ExtMethodApply(adapted).withType(adapted.tpe)
1022+
else adapted
1023+
SearchSuccess(returned, ref, cand.level)(ctx.typerState, ctx.gadt)
10731024
}
10741025
}}
10751026

@@ -1279,7 +1230,7 @@ trait Implicits { self: Typer =>
12791230
case _: AmbiguousImplicits => failure2
12801231
case _ =>
12811232
reason match {
1282-
case (_: DivergingImplicit) | (_: ShadowedImplicit) => failure
1233+
case (_: DivergingImplicit) => failure
12831234
case _ => List(failure, failure2).maxBy(_.tree.treeSize)
12841235
}
12851236
}

0 commit comments

Comments
 (0)