@@ -302,21 +302,31 @@ class Namer { typer: Typer =>
302
302
303
303
typr.println(i " creating symbol for $tree in ${ctx.mode}" )
304
304
305
- def checkNoConflict (name : Name ): Name = {
305
+ def checkNoConflict (name : Name ): Name =
306
306
def errorName (msg : => String ) = {
307
307
ctx.error(msg, tree.sourcePos)
308
308
name.freshened
309
309
}
310
+ def conflict (conflicting : Symbol ) =
311
+ val f = conflicting.associatedFile
312
+ val where = if f == null then " " else i " in $f"
313
+ errorName(i " $name is already defined as $conflicting$where" )
314
+
310
315
def preExisting = ctx.effectiveScope.lookup(name)
311
- if (ctx.owner.is(PackageClass ))
312
- if (preExisting.isDefinedInCurrentRun)
313
- errorName(s " ${preExisting.showLocated} has already been compiled once during this run " )
314
- else name
315
- else
316
- if ((! ctx.owner.isClass || name.isTypeName) && preExisting.exists)
317
- errorName(i " $name is already defined as $preExisting" )
316
+ if ctx.owner.is(PackageClass ) then
317
+ if preExisting.isDefinedInCurrentRun then conflict(preExisting)
318
318
else name
319
- }
319
+ else if ctx.owner.isPackageObject && name != nme.CONSTRUCTOR then
320
+ def conflicts (sym : Symbol ) =
321
+ sym.is(Package )
322
+ || sym.isDefinedInCurrentRun && sym.associatedFile != ctx.compilationUnit.source.file
323
+ ctx.owner.skipWeakOwner.info.member(name).altsWith(conflicts) match
324
+ case conflicting :: _ => conflict(conflicting.symbol)
325
+ case _ => name
326
+ else if (! ctx.owner.isClass || name.isTypeName) && preExisting.exists then
327
+ errorName(i " $name is already defined as $preExisting" )
328
+ else name
329
+ end checkNoConflict
320
330
321
331
/** Create new symbol or redefine existing symbol under lateCompile. */
322
332
def createOrRefine [S <: Symbol ](
0 commit comments