File tree Expand file tree Collapse file tree 2 files changed +27
-5
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -195,19 +195,30 @@ trait TypeAssigner {
195195 TryDynamicCallType
196196 } else {
197197 val alts = tpe.denot.alternatives.map(_.symbol).filter(_.exists)
198+ var packageAccess = false
198199 val what = alts match {
199200 case Nil =>
200- name.toString
201+ i " $ name cannot be accessed as a member of $pre "
201202 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+ }
203211 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 "
205213 }
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}"
207218 val whyNot = new StringBuffer
208219 alts foreach (_.isAccessibleFrom(pre, superAccess, whyNot))
209220 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)
211222 }
212223 }
213224 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