@@ -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 {
@@ -795,9 +781,6 @@ trait Implicits { self: Typer =>
795
781
shortForm
796
782
case _ =>
797
783
arg.tpe match {
798
- case tpe : ShadowedImplicit =>
799
- i """ $headline;
800
- | ${tpe.explanation}. """
801
784
case tpe : SearchFailureType =>
802
785
i """ $headline.
803
786
|I found:
@@ -1000,9 +983,9 @@ trait Implicits { self: Typer =>
1000
983
/** Try to typecheck an implicit reference */
1001
984
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 ) {
1002
985
val ref = cand.ref
1003
- var generated : Tree = tpd.ref(ref).withSpan(span.startPos)
986
+ val generated : Tree = tpd.ref(ref).withSpan(span.startPos)
1004
987
val locked = ctx.typerState.ownedVars
1005
- val generated1 =
988
+ val adapted =
1006
989
if (argument.isEmpty)
1007
990
adapt(generated, pt, locked)
1008
991
else {
@@ -1024,52 +1007,20 @@ trait Implicits { self: Typer =>
1024
1007
}
1025
1008
else tryConversion
1026
1009
}
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
-
1052
1010
if (ctx.reporter.hasErrors) {
1053
1011
ctx.reporter.removeBufferedMessages
1054
1012
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))
1058
1016
}
1059
1017
}
1060
1018
}
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
- }
1068
1019
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)
1073
1024
}
1074
1025
}}
1075
1026
@@ -1279,7 +1230,7 @@ trait Implicits { self: Typer =>
1279
1230
case _ : AmbiguousImplicits => failure2
1280
1231
case _ =>
1281
1232
reason match {
1282
- case (_ : DivergingImplicit ) | ( _ : ShadowedImplicit ) => failure
1233
+ case (_ : DivergingImplicit ) => failure
1283
1234
case _ => List (failure, failure2).maxBy(_.tree.treeSize)
1284
1235
}
1285
1236
}
0 commit comments