Skip to content

Commit f2e6d47

Browse files
committed
Improve error message for inaccessible types
1 parent ca6a80e commit f2e6d47

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2976,7 +2976,7 @@ extends ReferenceMsg(CannotBeAccessedID):
29762976
i"${if (sym.owner == pre.typeSymbol) sym.show else sym.showLocated} cannot"
29772977
case _ =>
29782978
i"none of the overloaded alternatives named $name can"
2979-
val where = if (ctx.owner.exists) s" from ${ctx.owner.enclosingClass}" else ""
2979+
val where = if (ctx.owner.exists) i" from ${ctx.owner.enclosingClass}" else ""
29802980
val whyNot = new StringBuffer
29812981
alts.foreach(_.isAccessibleFrom(pre, superAccess, whyNot))
29822982
i"$whatCanNot be accessed as a member of $pre$where.$whyNot"

tests/neg/i12573.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
| value getDFType is not a member of DFBits[(8 : Int)].
55
| Extension methods were tried, but the search failed with:
66
|
7-
| method getDFType cannot be accessed as a member of DFType.type from module class i12573$package$.
7+
| method getDFType cannot be accessed as a member of DFType.type from package object i12573$package.
88
| Access to protected method getDFType not permitted because enclosing package object i12573$package
9-
| is not a subclass of object DFType where target is defined
9+
| is not a subclass of object DFType where target is defined

tests/neg/not-accessible.check

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- [E173] Reference Error: tests/neg/not-accessible.scala:8:23 ---------------------------------------------------------
2+
8 | def test(a: A) = a.x // error
3+
| ^^^
4+
| value x cannot be accessed as a member of (a : foo.A) from class B.
5+
-- [E173] Reference Error: tests/neg/not-accessible.scala:10:23 --------------------------------------------------------
6+
10 | def test(a: A) = a.x // error
7+
| ^^^
8+
| value x cannot be accessed as a member of (a : foo.A) from object B.
9+
-- [E173] Reference Error: tests/neg/not-accessible.scala:13:23 --------------------------------------------------------
10+
13 | def test(a: A) = a.x // error
11+
| ^^^
12+
| value x cannot be accessed as a member of (a : foo.A) from package object not-accessible$package.
13+
-- [E173] Reference Error: tests/neg/not-accessible.scala:5:21 ---------------------------------------------------------
14+
5 | def test(a: A) = a.x // error
15+
| ^^^
16+
| value x cannot be accessed as a member of (a : foo.A) from package object not-accessible$package.
17+
-- [E173] Reference Error: tests/neg/not-accessible.scala:15:23 --------------------------------------------------------
18+
15 |def test(a: foo.A) = a.x // error
19+
| ^^^
20+
| value x cannot be accessed as a member of (a : foo.A) from package object not-accessible$package.

tests/neg/not-accessible.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package foo:
2+
3+
class A(private[A] val x: Int)
4+
5+
def test(a: A) = a.x // error
6+
7+
class B:
8+
def test(a: A) = a.x // error
9+
object B:
10+
def test(a: A) = a.x // error
11+
12+
package bar:
13+
def test(a: A) = a.x // error
14+
15+
def test(a: foo.A) = a.x // error

0 commit comments

Comments
 (0)