Skip to content

Commit

Permalink
Port 'unknown named enclosing class or object' error to new scheme
Browse files Browse the repository at this point in the history
Part of the effort documented in scala#1589 to port all error messages to
the new scheme.
  • Loading branch information
x3ro committed Oct 27, 2019
1 parent d2db509 commit 950a2e7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
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
|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)
}
}

0 comments on commit 950a2e7

Please sign in to comment.