File tree 4 files changed +32
-2
lines changed
test/dotty/tools/dotc/reporting
4 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -146,7 +146,8 @@ enum ErrorMessageID extends java.lang.Enum[ErrorMessageID] {
146
146
StableIdentPatternID ,
147
147
StaticFieldsShouldPrecedeNonStaticID ,
148
148
IllegalSuperAccessorID ,
149
- TraitParameterUsedAsParentPrefixID
149
+ TraitParameterUsedAsParentPrefixID ,
150
+ UnknownNamedEnclosingClassOrObjectID
150
151
151
152
def errorNumber = ordinal - 2
152
153
}
Original file line number Diff line number Diff line change @@ -2378,4 +2378,18 @@ object messages {
2378
2378
|than obtaining it from the parameters of ${cls.show}.
2379
2379
| """ .stripMargin
2380
2380
}
2381
+
2382
+ case class UnknownNamedEnclosingClassOrObject (name : TypeName )(implicit val ctx : Context )
2383
+ extends Message (UnknownNamedEnclosingClassOrObjectID ) {
2384
+ val kind : String = " Reference"
2385
+ val msg : String =
2386
+ em """ no enclosing class or object is named ' ${hl(name.show)}' """
2387
+ val explanation : String =
2388
+ ex """
2389
+ |The class or object named ' ${hl(name.show)}' was used as a visibility
2390
+ |modifier, but could not be resolved. Make sure that
2391
+ |' ${hl(name.show)}' is not misspelled and has been imported into the
2392
+ |current scope.
2393
+ """ .stripMargin
2394
+ }
2381
2395
}
Original file line number Diff line number Diff line change @@ -254,7 +254,7 @@ class Namer { typer: Typer =>
254
254
else {
255
255
val cls = ctx.owner.enclosingClassNamed(name)
256
256
if (! cls.exists)
257
- ctx.error(s " no enclosing class or object is named $ name" , ctx.source.atSpan(span))
257
+ ctx.error(UnknownNamedEnclosingClassOrObject ( name) , ctx.source.atSpan(span))
258
258
cls
259
259
}
260
260
Original file line number Diff line number Diff line change @@ -1657,4 +1657,19 @@ class ErrorMessagesTests extends ErrorMessagesTest {
1657
1657
messages.head.msg
1658
1658
)
1659
1659
}
1660
+
1661
+ @ Test def unknownNamedEnclosingClassOrObject () =
1662
+ checkMessagesAfter(RefChecks .name) {
1663
+ """
1664
+ |class TestObject {
1665
+ | private[doesNotExist] def test: Int = 5
1666
+ |}
1667
+ """ .stripMargin
1668
+ }
1669
+ .expect { (ictx, messages) =>
1670
+ implicit val ctx : Context = ictx
1671
+ assertMessageCount(1 , messages)
1672
+ val UnknownNamedEnclosingClassOrObject (name) :: Nil = messages
1673
+ assertEquals(" doesNotExist" , name.show)
1674
+ }
1660
1675
}
You can’t perform that action at this time.
0 commit comments