@@ -16,6 +16,7 @@ import Mode.ImplicitsEnabled
16
16
import NameOps ._
17
17
import NameKinds .LazyImplicitName
18
18
import Symbols ._
19
+ import Denotations ._
19
20
import Types ._
20
21
import Decorators ._
21
22
import Names ._
@@ -907,12 +908,6 @@ trait Implicits { self: Typer =>
907
908
/** The expected type for the searched implicit */
908
909
lazy val fullProto : Type = implicitProto(pt, identity)
909
910
910
- lazy val funProto : Type = fullProto match {
911
- case proto : ViewProto =>
912
- FunProto (untpd.TypedSplice (dummyTreeOfType(proto.argType)) :: Nil , proto.resultType)(self)
913
- case proto => proto
914
- }
915
-
916
911
/** The expected type where parameters and uninstantiated typevars are replaced by wildcard types */
917
912
val wildProto : Type = implicitProto(pt, wildApprox(_))
918
913
@@ -930,18 +925,31 @@ trait Implicits { self: Typer =>
930
925
untpd.Apply (untpd.TypedSplice (generated), untpd.TypedSplice (argument) :: Nil ),
931
926
pt, locked)
932
927
val generated1 = adapt(generated, pt, locked)
928
+
933
929
lazy val shadowing =
934
- typed (untpd.Ident (cand.implicitRef.implicitName) withPos pos.toSynthetic, funProto )(
930
+ typedUnadapted (untpd.Ident (cand.implicitRef.implicitName) withPos pos.toSynthetic)(
935
931
nestedContext().addMode(Mode .ImplicitShadowing ).setExploreTyperState())
936
- def refSameAs (shadowing : Tree ): Boolean =
937
- ref.symbol == closureBody(shadowing).symbol || {
938
- shadowing match {
939
- case Trees .Select (qual, nme.apply) => refSameAs(qual)
940
- case Trees .Apply (fn, _) => refSameAs(fn)
941
- case Trees .TypeApply (fn, _) => refSameAs(fn)
942
- case _ => false
943
- }
932
+
933
+ /** Is candidate reference the same as the `shadowing` reference? (i.e.
934
+ * no actual shadowing occured). This is the case if the
935
+ * underlying symbol of the shadowing reference is the same as the
936
+ * symbol of the candidate reference, or if they have a common type owner.
937
+ *
938
+ * The second condition (same owner) is needed because the candidate reference
939
+ * and the potential shadowing reference are typechecked with different prototypes.
940
+ * so might yield different overloaded symbols. E.g. if the candidate reference
941
+ * is to an implicit conversion generated from an implicit class, the shadowing
942
+ * reference could go to the companion object of that class instead.
943
+ */
944
+ def refSameAs (shadowing : Tree ): Boolean = {
945
+ def symMatches (sym : Symbol ): Boolean =
946
+ sym == ref.symbol || sym.owner.isType && sym.owner == ref.symbol.owner
947
+ def denotMatches (d : Denotation ): Boolean = d match {
948
+ case d : SingleDenotation => symMatches(d.symbol)
949
+ case d => d.hasAltWith(denotMatches(_))
944
950
}
951
+ denotMatches(closureBody(shadowing).denot)
952
+ }
945
953
946
954
if (ctx.reporter.hasErrors) {
947
955
ctx.reporter.removeBufferedMessages
0 commit comments