@@ -437,20 +437,6 @@ object Implicits {
437
437
em " ${err.refStr(ref)} does not $qualify"
438
438
}
439
439
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
-
454
440
class DivergingImplicit (ref : TermRef ,
455
441
val expectedType : Type ,
456
442
val argument : Tree ) extends SearchFailureType {
@@ -836,9 +822,6 @@ trait Implicits { self: Typer =>
836
822
shortForm
837
823
case _ =>
838
824
arg.tpe match {
839
- case tpe : ShadowedImplicit =>
840
- i """ $headline;
841
- | ${tpe.explanation}. """
842
825
case tpe : SearchFailureType =>
843
826
i """ $headline.
844
827
|I found:
@@ -1047,9 +1030,9 @@ trait Implicits { self: Typer =>
1047
1030
/** Try to typecheck an implicit reference */
1048
1031
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 ) {
1049
1032
val ref = cand.ref
1050
- var generated : Tree = tpd.ref(ref).withSpan(span.startPos)
1033
+ val generated : Tree = tpd.ref(ref).withSpan(span.startPos)
1051
1034
val locked = ctx.typerState.ownedVars
1052
- val generated1 =
1035
+ val adapted =
1053
1036
if (argument.isEmpty)
1054
1037
adapt(generated, pt, locked)
1055
1038
else {
@@ -1071,52 +1054,20 @@ trait Implicits { self: Typer =>
1071
1054
}
1072
1055
else tryConversion
1073
1056
}
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
-
1099
1057
if (ctx.reporter.hasErrors) {
1100
1058
ctx.reporter.removeBufferedMessages
1101
1059
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))
1105
1063
}
1106
1064
}
1107
1065
}
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
- }
1115
1066
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)
1120
1071
}
1121
1072
}}
1122
1073
@@ -1326,7 +1277,7 @@ trait Implicits { self: Typer =>
1326
1277
case _ : AmbiguousImplicits => failure2
1327
1278
case _ =>
1328
1279
reason match {
1329
- case (_ : DivergingImplicit ) | ( _ : ShadowedImplicit ) => failure
1280
+ case (_ : DivergingImplicit ) => failure
1330
1281
case _ => List (failure, failure2).maxBy(_.tree.treeSize)
1331
1282
}
1332
1283
}
0 commit comments