@@ -99,6 +99,8 @@ object Implicits {
99
99
if (wtp.derivesFrom(SingletonClass )) defn.AnyType else wtp
100
100
}
101
101
102
+ protected def isAccessible (ref : TermRef )(using Context ): Boolean
103
+
102
104
/** Return those references in `refs` that are compatible with type `pt`. */
103
105
protected def filterMatching (pt : Type )(using Context ): List [Candidate ] = {
104
106
record(" filterMatching" )
@@ -197,7 +199,8 @@ object Implicits {
197
199
case _ => tp
198
200
199
201
var ckind =
200
- if (! ref.symbol.isAccessibleFrom(ref.prefix)) Candidate .None
202
+ if ! isAccessible(ref) then
203
+ Candidate .None
201
204
else pt match {
202
205
case pt : ViewProto =>
203
206
viewCandidateKind(ref.widen, pt.argType, pt.resType)
@@ -244,7 +247,9 @@ object Implicits {
244
247
*/
245
248
class OfTypeImplicits (tp : Type , val companionRefs : TermRefSet )(initctx : Context ) extends ImplicitRefs (initctx) {
246
249
assert(initctx.typer != null )
247
- implicits.println(i " implicits of type $tp = ${companionRefs.toList}%, % " )
250
+
251
+ implicits.println(i " implicit scope of type $tp = ${companionRefs.toList}%, % " )
252
+
248
253
@ threadUnsafe lazy val refs : List [ImplicitRef ] = {
249
254
val buf = new mutable.ListBuffer [TermRef ]
250
255
for (companion <- companionRefs) buf ++= companion.implicitMembers
@@ -258,6 +263,9 @@ object Implicits {
258
263
filterMatching(tp)
259
264
}
260
265
266
+ override def isAccessible (ref : TermRef )(using Context ): Boolean =
267
+ ref.symbol.exists && ! ref.symbol.is(Private )
268
+
261
269
override def toString : String =
262
270
i " OfTypeImplicits( $tp), companions = ${companionRefs.toList}%, %; refs = $refs%, %. "
263
271
}
@@ -325,6 +333,9 @@ object Implicits {
325
333
}
326
334
}
327
335
336
+ override def isAccessible (ref : TermRef )(using Context ): Boolean =
337
+ ref.symbol.isAccessibleFrom(ref.prefix)
338
+
328
339
override def toString : String = {
329
340
val own = i " (implicits: $refs%, %) "
330
341
if (isOuterMost) own else own + " \n " + outerImplicits
@@ -967,7 +978,9 @@ trait Implicits { self: Typer =>
967
978
case _ =>
968
979
tryConversion
969
980
}
970
- if (ctx.reporter.hasErrors) {
981
+ if ctx.reporter.hasErrors
982
+ || ! cand.ref.symbol.isAccessibleFrom(cand.ref.prefix)
983
+ then
971
984
ctx.reporter.removeBufferedMessages
972
985
adapted.tpe match {
973
986
case _ : SearchFailureType => SearchFailure (adapted)
@@ -979,13 +992,11 @@ trait Implicits { self: Typer =>
979
992
else
980
993
SearchFailure (adapted.withType(new MismatchedImplicit (ref, pt, argument)))
981
994
}
982
- }
983
- else {
995
+ else
984
996
val returned =
985
997
if (cand.isExtension) Applications .ExtMethodApply (adapted)
986
998
else adapted
987
999
SearchSuccess (returned, ref, cand.level)(ctx.typerState, ctx.gadt)
988
- }
989
1000
}
990
1001
991
1002
/** An implicit search; parameters as in `inferImplicit` */
@@ -1010,8 +1021,6 @@ trait Implicits { self: Typer =>
1010
1021
1011
1022
val isNot : Boolean = wildProto.classSymbol == defn.NotClass
1012
1023
1013
- // println(i"search implicits $pt / ${eligible.map(_.ref)}")
1014
-
1015
1024
/** Try to type-check implicit reference, after checking that this is not
1016
1025
* a diverging search
1017
1026
*/
0 commit comments