Skip to content

Port 'unknown named enclosing class or object' error to new scheme #7457

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ enum ErrorMessageID extends java.lang.Enum[ErrorMessageID] {
StableIdentPatternID,
StaticFieldsShouldPrecedeNonStaticID,
IllegalSuperAccessorID,
TraitParameterUsedAsParentPrefixID
TraitParameterUsedAsParentPrefixID,
UnknownNamedEnclosingClassOrObjectID

def errorNumber = ordinal - 2
}
14 changes: 14 additions & 0 deletions compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2378,4 +2378,18 @@ object messages {
|than obtaining it from the parameters of ${cls.show}.
|""".stripMargin
}

case class UnknownNamedEnclosingClassOrObject(name: TypeName)(implicit val ctx: Context)
extends Message(UnknownNamedEnclosingClassOrObjectID) {
val kind: String = "Reference"
val msg: String =
em"""no enclosing class or object is named '${hl(name.show)}'"""
val explanation: String =
ex"""
|The class or object named '${hl(name.show)}' was used a visibility
Copy link
Contributor

Choose a reason for hiding this comment

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

used as a visibility modifier

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, thanks!

|modifier, but could not be resolved. Make sure that
|'${hl(name.show)}' is not misspelled and has been imported into the
|current scope.
""".stripMargin
}
}
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class Namer { typer: Typer =>
else {
val cls = ctx.owner.enclosingClassNamed(name)
if (!cls.exists)
ctx.error(s"no enclosing class or object is named $name", ctx.source.atSpan(span))
ctx.error(UnknownNamedEnclosingClassOrObject(name), ctx.source.atSpan(span))
cls
}

Expand Down
15 changes: 15 additions & 0 deletions compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1657,4 +1657,19 @@ class ErrorMessagesTests extends ErrorMessagesTest {
messages.head.msg
)
}

@Test def unknownNamedEnclosingClassOrObject() =
checkMessagesAfter(RefChecks.name) {
"""
|class TestObject {
| private[doesNotExist] def test: Int = 5
|}
""".stripMargin
}
.expect { (ictx, messages) =>
implicit val ctx: Context = ictx
assertMessageCount(1, messages)
val UnknownNamedEnclosingClassOrObject(name) :: Nil = messages
assertEquals("doesNotExist", name.show)
}
}