@@ -100,6 +100,8 @@ object Implicits {
100
100
if (wtp.derivesFrom(SingletonClass )) defn.AnyType else wtp
101
101
}
102
102
103
+ protected def isAccessible (ref : TermRef )(using Context ): Boolean
104
+
103
105
/** Return those references in `refs` that are compatible with type `pt`. */
104
106
protected def filterMatching (pt : Type )(using Context ): List [Candidate ] = {
105
107
record(" filterMatching" )
@@ -198,7 +200,8 @@ object Implicits {
198
200
case _ => tp
199
201
200
202
var ckind =
201
- if (! ref.symbol.isAccessibleFrom(ref.prefix)) Candidate .None
203
+ if ! isAccessible(ref) then
204
+ Candidate .None
202
205
else pt match {
203
206
case pt : ViewProto =>
204
207
viewCandidateKind(ref.widen, pt.argType, pt.resType)
@@ -259,6 +262,9 @@ object Implicits {
259
262
filterMatching(tp)
260
263
}
261
264
265
+ override def isAccessible (ref : TermRef )(using Context ): Boolean =
266
+ ref.symbol.exists && ! ref.symbol.is(Private )
267
+
262
268
override def toString : String =
263
269
i " OfTypeImplicits( $tp), companions = ${companionRefs.toList}%, %; refs = $refs%, %. "
264
270
}
@@ -326,6 +332,9 @@ object Implicits {
326
332
}
327
333
}
328
334
335
+ override def isAccessible (ref : TermRef )(using Context ): Boolean =
336
+ ref.symbol.isAccessibleFrom(ref.prefix)
337
+
329
338
override def toString : String = {
330
339
val own = i " (implicits: $refs%, %) "
331
340
if (isOuterMost) own else own + " \n " + outerImplicits
@@ -960,7 +969,6 @@ trait Implicits { self: Typer =>
960
969
implicits.println(i " committing ${result.tstate.constraint} yielding ${ctx.typerState.constraint} in ${ctx.typerState}" )
961
970
result
962
971
case result : SearchFailure if result.isAmbiguous =>
963
- // println(i"FAIL for $pt / $argument: $result0")
964
972
val deepPt = pt.deepenProto
965
973
if (deepPt ne pt) inferImplicit(deepPt, argument, span)
966
974
else if (migrateTo3 && ! ctx.mode.is(Mode .OldOverloadingResolution ))
@@ -975,10 +983,8 @@ trait Implicits { self: Typer =>
975
983
}
976
984
else result
977
985
case NoMatchingImplicitsFailure =>
978
- // println(i"FAIL for $pt / $argument: $result0")
979
986
SearchFailure (new NoMatchingImplicits (pt, argument, ctx.typerState.constraint))
980
987
case _ =>
981
- // println(i"FAIL for $pt / $argument: $result0")
982
988
result0
983
989
}
984
990
// If we are at the outermost implicit search then emit the implicit dictionary, if any.
@@ -1024,7 +1030,9 @@ trait Implicits { self: Typer =>
1024
1030
case _ =>
1025
1031
tryConversion
1026
1032
}
1027
- if (ctx.reporter.hasErrors) {
1033
+ if ctx.reporter.hasErrors
1034
+ || ! cand.ref.symbol.isAccessibleFrom(cand.ref.prefix)
1035
+ then
1028
1036
ctx.reporter.removeBufferedMessages
1029
1037
adapted.tpe match {
1030
1038
case _ : SearchFailureType => SearchFailure (adapted)
@@ -1036,13 +1044,11 @@ trait Implicits { self: Typer =>
1036
1044
else
1037
1045
SearchFailure (adapted.withType(new MismatchedImplicit (ref, pt, argument)))
1038
1046
}
1039
- }
1040
- else {
1047
+ else
1041
1048
val returned =
1042
1049
if (cand.isExtension) Applications .ExtMethodApply (adapted)
1043
1050
else adapted
1044
1051
SearchSuccess (returned, ref, cand.level)(ctx.typerState, ctx.gadt)
1045
- }
1046
1052
}
1047
1053
1048
1054
/** An implicit search; parameters as in `inferImplicit` */
@@ -1067,8 +1073,6 @@ trait Implicits { self: Typer =>
1067
1073
1068
1074
val isNot : Boolean = wildProto.classSymbol == defn.NotClass
1069
1075
1070
- // println(i"search implicits $pt / ${eligible.map(_.ref)}")
1071
-
1072
1076
/** Try to type-check implicit reference, after checking that this is not
1073
1077
* a diverging search
1074
1078
*/
0 commit comments