Skip to content

Commit

Permalink
Merge pull request scala#7457 from x3ro/lucas/unknown-named-class-or-…
Browse files Browse the repository at this point in the history
…object

Port 'unknown named enclosing class or object' error to new scheme
  • Loading branch information
OlivierBlanvillain authored Oct 28, 2019
2 parents e2a4e64 + aae3e6a commit 169e1db
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 as 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 169e1db

Please sign in to comment.