Skip to content

Commit 2a53d16

Browse files
committed
Drop logic for shadowed implicits checking
1 parent e78fc93 commit 2a53d16

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 {
@@ -836,9 +822,6 @@ trait Implicits { self: Typer =>
836822
shortForm
837823
case _ =>
838824
arg.tpe match {
839-
case tpe: ShadowedImplicit =>
840-
i"""$headline;
841-
|${tpe.explanation}."""
842825
case tpe: SearchFailureType =>
843826
i"""$headline.
844827
|I found:
@@ -1047,9 +1030,9 @@ trait Implicits { self: Typer =>
10471030
/** Try to typecheck an implicit reference */
10481031
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) {
10491032
val ref = cand.ref
1050-
var generated: Tree = tpd.ref(ref).withSpan(span.startPos)
1033+
val generated: Tree = tpd.ref(ref).withSpan(span.startPos)
10511034
val locked = ctx.typerState.ownedVars
1052-
val generated1 =
1035+
val adapted =
10531036
if (argument.isEmpty)
10541037
adapt(generated, pt, locked)
10551038
else {
@@ -1071,52 +1054,20 @@ trait Implicits { self: Typer =>
10711054
}
10721055
else tryConversion
10731056
}
1074-
lazy val shadowing =
1075-
typedUnadapted(untpd.Ident(cand.implicitRef.implicitName).withSpan(span.toSynthetic))(
1076-
nestedContext().addMode(Mode.ImplicitShadowing).setExploreTyperState())
1077-
1078-
/** Is candidate reference the same as the `shadowing` reference? (i.e.
1079-
* no actual shadowing occured). This is the case if the
1080-
* underlying symbol of the shadowing reference is the same as the
1081-
* symbol of the candidate reference, or if they have a common type owner.
1082-
*
1083-
* The second condition (same owner) is needed because the candidate reference
1084-
* and the potential shadowing reference are typechecked with different prototypes.
1085-
* so might yield different overloaded symbols. E.g. if the candidate reference
1086-
* is to an implicit conversion generated from an implicit class, the shadowing
1087-
* reference could go to the companion object of that class instead.
1088-
*/
1089-
def refSameAs(shadowing: Tree): Boolean = {
1090-
def symMatches(sym: Symbol): Boolean =
1091-
sym == ref.symbol || sym.owner.isType && sym.owner == ref.symbol.owner
1092-
def denotMatches(d: Denotation): Boolean = d match {
1093-
case d: SingleDenotation => symMatches(d.symbol)
1094-
case d => d.hasAltWith(denotMatches(_))
1095-
}
1096-
denotMatches(closureBody(shadowing).denot)
1097-
}
1098-
10991057
if (ctx.reporter.hasErrors) {
11001058
ctx.reporter.removeBufferedMessages
11011059
SearchFailure {
1102-
generated1.tpe match {
1103-
case _: SearchFailureType => generated1
1104-
case _ => generated1.withType(new MismatchedImplicit(ref, pt, argument))
1060+
adapted.tpe match {
1061+
case _: SearchFailureType => adapted
1062+
case _ => adapted.withType(new MismatchedImplicit(ref, pt, argument))
11051063
}
11061064
}
11071065
}
1108-
else if (false &&
1109-
contextual && !ctx.mode.is(Mode.ImplicitShadowing) &&
1110-
!shadowing.tpe.isError && !refSameAs(shadowing)) {
1111-
implicits.println(i"SHADOWING $ref in ${ref.termSymbol.maybeOwner} is shadowed by $shadowing in ${shadowing.symbol.maybeOwner}")
1112-
SearchFailure(generated1.withTypeUnchecked(
1113-
new ShadowedImplicit(ref, methPart(shadowing).tpe, pt, argument)))
1114-
}
11151066
else {
1116-
val generated2 =
1117-
if (cand.isExtension) Applications.ExtMethodApply(generated1).withType(generated1.tpe)
1118-
else generated1
1119-
SearchSuccess(generated2, ref, cand.level)(ctx.typerState, ctx.gadt)
1067+
val returned =
1068+
if (cand.isExtension) Applications.ExtMethodApply(adapted).withType(adapted.tpe)
1069+
else adapted
1070+
SearchSuccess(returned, ref, cand.level)(ctx.typerState, ctx.gadt)
11201071
}
11211072
}}
11221073

@@ -1326,7 +1277,7 @@ trait Implicits { self: Typer =>
13261277
case _: AmbiguousImplicits => failure2
13271278
case _ =>
13281279
reason match {
1329-
case (_: DivergingImplicit) | (_: ShadowedImplicit) => failure
1280+
case (_: DivergingImplicit) => failure
13301281
case _ => List(failure, failure2).maxBy(_.tree.treeSize)
13311282
}
13321283
}

0 commit comments

Comments
 (0)