File tree 2 files changed +11
-5
lines changed
compiler/src/dotty/tools/dotc
2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -1908,10 +1908,15 @@ object messages {
1908
1908
}
1909
1909
1910
1910
case class PackageNameAlreadyDefined (pkg : Symbol )(implicit ctx : Context ) extends Message (PackageNameAlreadyDefinedID ) {
1911
- val msg : String = em " ${pkg} is already defined, cannot be a ${hl(" package" )}"
1911
+ val (where, or) =
1912
+ if pkg.associatedFile == null then (" " , " " )
1913
+ else (s " in ${pkg.associatedFile}" , " or delete the containing class file" )
1914
+ val msg : String = em """ ${pkg.name} is the name of $pkg$where.
1915
+ |It cannot be used at the same time as the name of a package. """
1912
1916
val kind : String = " Naming"
1913
1917
val explanation : String =
1914
- em " An ${hl(" object" )} cannot have the same name as an existing ${hl(" package" )}. Rename either one of them. "
1918
+ em """ An ${hl(" object" )} or other toplevel definition cannot have the same name as an existing ${hl(" package" )}.
1919
+ |Rename either one of them $or. """
1915
1920
}
1916
1921
1917
1922
case class UnapplyInvalidNumberOfArguments (qual : untpd.Tree , argTypes : List [Type ])(implicit ctx : Context )
Original file line number Diff line number Diff line change @@ -1879,16 +1879,17 @@ class Typer extends Namer
1879
1879
val pid1 = typedExpr(tree.pid, AnySelectionProto )(ctx.addMode(Mode .InPackageClauseName ))
1880
1880
val pkg = pid1.symbol
1881
1881
pid1 match {
1882
- case pid1 : RefTree if pkg.exists =>
1883
- if (! pkg.is(Package )) ctx.error(PackageNameAlreadyDefined (pkg), tree.sourcePos)
1882
+ case pid1 : RefTree if pkg.is(Package ) =>
1884
1883
val packageCtx = ctx.packageContext(tree, pkg)
1885
1884
var stats1 = typedStats(tree.stats, pkg.moduleClass)(packageCtx)._1
1886
1885
if (! ctx.isAfterTyper)
1887
1886
stats1 = stats1 ++ typedBlockStats(MainProxies .mainProxies(stats1))(packageCtx)._1
1888
1887
cpy.PackageDef (tree)(pid1, stats1).withType(pkg.termRef)
1889
1888
case _ =>
1890
1889
// Package will not exist if a duplicate type has already been entered, see `tests/neg/1708.scala`
1891
- errorTree(tree, i " package ${tree.pid.name} does not exist " )
1890
+ errorTree(tree,
1891
+ if pkg.exists then PackageNameAlreadyDefined (pkg)
1892
+ else i " package ${tree.pid.name} does not exist " )
1892
1893
}
1893
1894
}
1894
1895
You can’t perform that action at this time.
0 commit comments