Skip to content

Commit c878f81

Browse files
committed
Fix #2066: Don't qualify private members in SelectionProto's...
... unless they would be accessible in the given context.
1 parent b2d3b89 commit c878f81

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,10 @@ object SymDenotations {
957957
else
958958
companionNamed(name)(ctx.outersIterator.dropWhile(_.scope eq ctx.scope).next)
959959

960+
/** Is this symbol the same or a linked class of `sym`? */
961+
final def isLinkedWith(sym: Symbol)(implicit ctx: Context): Boolean =
962+
(symbol eq sym) || (linkedClass eq sym)
963+
960964
/** If this is a class, the module class of its companion object.
961965
* If this is a module class, its companion class.
962966
* NoSymbol otherwise.

compiler/src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,13 @@ object TypeErasure {
215215
}
216216

217217
/** The erased least upper bound is computed as follows
218-
* - if both argument are arrays of objects, an array of the lub of the element types
218+
* - if both argument are arrays of objects, an array of the erased lub of the element types
219219
* - if both arguments are arrays of same primitives, an array of this primitive
220220
* - if one argument is array of primitives and the other is array of objects, Object
221221
* - if one argument is an array, Object
222222
* - otherwise a common superclass or trait S of the argument classes, with the
223223
* following two properties:
224-
* S is minimal: no other common superclass or trait derives from S]
224+
* S is minimal: no other common superclass or trait derives from S
225225
* S is last : in the linearization of the first argument type `tp1`
226226
* there are no minimal common superclasses or traits that
227227
* come after S.

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ object ProtoTypes {
9595

9696
override def isMatchedBy(tp1: Type)(implicit ctx: Context) = {
9797
name == nme.WILDCARD || {
98-
val mbr = tp1.member(name)
98+
val mbr =
99+
if (tp1.widen.classSymbol.isLinkedWith(ctx.owner.enclosingClass)) tp1.member(name)
100+
else tp1.nonPrivateMember(name)
99101
def qualifies(m: SingleDenotation) =
100102
memberProto.isRef(defn.UnitClass) ||
101103
compat.normalizedCompatible(m.info, memberProto)

tests/pos/i2066.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Foo
2+
3+
object Test {
4+
implicit class One(x: Foo) {
5+
def meth: Unit = {}
6+
}
7+
8+
implicit class Two(x: Foo) {
9+
private def meth: Unit = {}
10+
}
11+
12+
def test(foo: Foo): Unit = {
13+
foo.meth
14+
}
15+
}

0 commit comments

Comments
 (0)