File tree Expand file tree Collapse file tree 4 files changed +26
-2
lines changed
test/dotty/tools/dotc/reporting Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -109,7 +109,8 @@ public enum ErrorMessageID {
109109 OnlyFunctionsCanBeFollowedByUnderscoreID ,
110110 MissingEmptyArgumentListID ,
111111 DuplicateNamedTypeParameterID ,
112- UndefinedNamedTypeParameterID
112+ UndefinedNamedTypeParameterID ,
113+ PackageNameAlreadyDefinedID
113114 ;
114115
115116 public int errorNumber () {
Original file line number Diff line number Diff line change @@ -1879,4 +1879,12 @@ object messages {
18791879 val msg = hl " Type parameter $undefinedName is undefined. Expected one of ${definedNames.map(_.show).mkString(" , " )}. "
18801880 val explanation = " "
18811881 }
1882+
1883+ case class PackageNameAlreadyDefined (pkg : Symbol )(implicit ctx : Context ) extends Message (PackageNameAlreadyDefinedID ) {
1884+
1885+ override def msg : String = hl " ${pkg} is already defined, cannot be a package "
1886+ override def kind : String = " Syntax"
1887+ override def explanation : String =
1888+ " An object cannot have the same name as an existing package. Rename ${pkg} or the package with the same name."
1889+ }
18821890}
Original file line number Diff line number Diff line change @@ -1516,7 +1516,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
15161516 val packageContext =
15171517 if (pkg is Package ) ctx.fresh.setOwner(pkg.moduleClass).setTree(tree)
15181518 else {
1519- ctx.error(em " $ pkg is already defined, cannot be a package " , tree.pos)
1519+ ctx.error(PackageNameAlreadyDefined ( pkg) , tree.pos)
15201520 ctx
15211521 }
15221522 val stats1 = typedStats(tree.stats, pkg.moduleClass)(packageContext)
Original file line number Diff line number Diff line change 11package dotty .tools
2+
23package dotc
34package reporting
45
@@ -1132,4 +1133,18 @@ class ErrorMessagesTests extends ErrorMessagesTest {
11321133 assertEquals(tpParams, l2.map(_.show))
11331134
11341135 }
1136+
1137+ @ Test def packageNameAlreadyDefined =
1138+ checkMessagesAfter(" frontend" ) {
1139+ """
1140+ |package bar { }
1141+ |object bar { }
1142+ |
1143+ """ .stripMargin
1144+ }.expect { (ictx, messages) =>
1145+ implicit val ctx : Context = ictx
1146+
1147+ assertMessageCount(1 , messages)
1148+ assert(messages.head.isInstanceOf [PackageNameAlreadyDefined ])
1149+ }
11351150}
You can’t perform that action at this time.
0 commit comments