File tree 3 files changed +31
-10
lines changed
compiler/src/dotty/tools/dotc
3 files changed +31
-10
lines changed Original file line number Diff line number Diff line change @@ -674,10 +674,7 @@ object SymDenotations {
674
674
final def isAccessibleFrom (pre : Type , superAccess : Boolean = false , whyNot : StringBuffer = null )(implicit ctx : Context ): Boolean = {
675
675
676
676
/** Are we inside definition of `boundary`? */
677
- def accessWithin (boundary : Symbol ) =
678
- ctx.owner.isContainedIn(boundary) &&
679
- (! (this is JavaDefined ) || // disregard package nesting for Java
680
- ctx.owner.enclosingPackageClass == boundary.enclosingPackageClass)
677
+ def accessWithin (boundary : Symbol ) = ctx.owner.isContainedIn(boundary)
681
678
682
679
/** Are we within definition of linked class of `boundary`? */
683
680
def accessWithinLinked (boundary : Symbol ) = {
@@ -733,7 +730,9 @@ object SymDenotations {
733
730
( ! (this is Local )
734
731
|| (owner is ImplClass ) // allow private local accesses to impl class members
735
732
|| isCorrectThisType(pre)
736
- )
733
+ ) &&
734
+ (! (this .is(Private ) && owner.is(Package )) ||
735
+ owner == ctx.owner.enclosingPackageClass)
737
736
|| (this is Protected ) &&
738
737
( superAccess
739
738
|| pre.isInstanceOf [ThisType ]
Original file line number Diff line number Diff line change @@ -195,19 +195,30 @@ trait TypeAssigner {
195
195
TryDynamicCallType
196
196
} else {
197
197
val alts = tpe.denot.alternatives.map(_.symbol).filter(_.exists)
198
+ var packageAccess = false
198
199
val what = alts match {
199
200
case Nil =>
200
- name.toString
201
+ i " $ name cannot be accessed as a member of $pre "
201
202
case sym :: Nil =>
202
- if (sym.owner == pre.typeSymbol) sym.show else sym.showLocated
203
+ if (sym.owner.is(Package )) {
204
+ packageAccess = true
205
+ i " ${sym.showLocated} cannot be accessed "
206
+ }
207
+ else {
208
+ val symStr = if (sym.owner == pre.typeSymbol) sym.show else sym.showLocated
209
+ i " $symStr cannot be accessed as a member of $pre"
210
+ }
203
211
case _ =>
204
- em " none of the overloaded alternatives named $name"
212
+ em " none of the overloaded alternatives named $name can be accessed as members of $pre "
205
213
}
206
- val where = if (ctx.owner.exists) s " from ${ctx.owner.enclosingClass}" else " "
214
+ val where =
215
+ if (! ctx.owner.exists) " "
216
+ else if (packageAccess) i " from nested ${ctx.owner.enclosingPackageClass}"
217
+ else i " from ${ctx.owner.enclosingClass}"
207
218
val whyNot = new StringBuffer
208
219
alts foreach (_.isAccessibleFrom(pre, superAccess, whyNot))
209
220
if (tpe.isError) tpe
210
- else errorType(ex " $what cannot be accessed as a member of $pre $where. $whyNot" , pos)
221
+ else errorType(ex " $what$where. $whyNot" , pos)
211
222
}
212
223
}
213
224
else ctx.makePackageObjPrefixExplicit(tpe withDenot d)
Original file line number Diff line number Diff line change
1
+ package outer {
2
+ private class A
3
+
4
+ package inner {
5
+ object Test {
6
+ def main (args : Array [String ]): Unit = {
7
+ println(new A ) // error: cannot access
8
+ }
9
+ }
10
+ }
11
+ }
You can’t perform that action at this time.
0 commit comments