Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly format enclosing class of private access error message #18688

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ extends Message(PatternMatchExhaustivityID) {

val pathes = List(
ActionPatch(
srcPos = endPos,
srcPos = endPos,
replacement = uncoveredCases.map(c => indent(s"case $c => ???", startColumn))
.mkString("\n", "\n", "")
),
Expand Down Expand Up @@ -2984,7 +2984,7 @@ extends ReferenceMsg(CannotBeAccessedID):
i"${if (sym.owner == pre.typeSymbol) sym.show else sym.showLocated} cannot"
case _ =>
i"none of the overloaded alternatives named $name can"
val where = if (ctx.owner.exists) s" from ${ctx.owner.enclosingClass}" else ""
val where = if (ctx.owner.exists) i" from ${ctx.owner.enclosingClass}" else ""
val whyNot = new StringBuffer
alts.foreach(_.isAccessibleFrom(pre, superAccess, whyNot))
i"$whatCanNot be accessed as a member of $pre$where.$whyNot"
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/i12573.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
| value getDFType is not a member of DFBits[(8 : Int)].
| Extension methods were tried, but the search failed with:
|
| method getDFType cannot be accessed as a member of DFType.type from module class i12573$package$.
| method getDFType cannot be accessed as a member of DFType.type from package object i12573$package.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are further improvements on this error message pending in #18406.

| Access to protected method getDFType not permitted because enclosing package object i12573$package
| is not a subclass of object DFType where target is defined
| is not a subclass of object DFType where target is defined
4 changes: 4 additions & 0 deletions tests/neg/i18686.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- [E173] Reference Error: tests/neg/i18686.scala:7:16 -----------------------------------------------------------------
7 | println(Foo.Bar) // error
| ^^^^^^^
| value Bar cannot be accessed as a member of Foo.type from object Main.
9 changes: 9 additions & 0 deletions tests/neg/i18686.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
object Foo:
private val Bar: Int = 3
end Foo

object Main:
def main(args: Array[String]): Unit =
println(Foo.Bar) // error
end main
end Main