@@ -302,6 +302,12 @@ class Namer { typer: Typer =>
302
302
303
303
typr.println(i " creating symbol for $tree in ${ctx.mode}" )
304
304
305
+ /** Check that a new definition with given name and privacy status
306
+ * in current context would not conflict with existing currently
307
+ * compiled definitions.
308
+ * The logic here is very subtle and fragile due to the fact that
309
+ * we are not allowed to force anything.
310
+ */
305
311
def checkNoConflict (name : Name , isPrivate : Boolean ): Name =
306
312
val owner = ctx.owner
307
313
var conflictsDetected = false
@@ -314,24 +320,21 @@ class Namer { typer: Typer =>
314
320
ctx.error(i " $name is already defined as $conflicting$where" , tree.sourcePos)
315
321
conflictsDetected = true
316
322
317
- def checkNoConflictWith (preExisting : Symbol ) =
323
+ def checkNoConflictIn (preExisting : Symbol ) =
324
+ val preExisting = owner.unforcedDecls.lookup(name)
318
325
if (preExisting.isDefinedInCurrentRun || preExisting.lastKnownDenotation.is(Package ))
319
326
&& (! preExisting.lastKnownDenotation.is(Private ) || preExisting.owner.is(Package ))
320
327
then conflict(preExisting)
321
328
322
- def checkNoConflictIn (owner : Symbol ) =
323
- checkNoConflictWith( owner.unforcedDecls.lookup(name))
324
-
325
329
def pkgObjs (pkg : Symbol ) =
326
330
pkg.denot.asInstanceOf [PackageClassDenotation ].packageObjs.map(_.symbol)
327
331
328
- def preExisting = ctx.effectiveScope.lookup(name)
329
332
if owner.is(PackageClass ) then
330
- checkNoConflictWith(preExisting)
331
- return name
333
+ checkNoConflictIn(owner)
332
334
for pkgObj <- pkgObjs(owner) do
333
335
checkNoConflictIn(pkgObj)
334
336
else
337
+ def preExisting = ctx.effectiveScope.lookup(name)
335
338
if (! owner.isClass || name.isTypeName) && preExisting.exists then
336
339
conflict(preExisting)
337
340
else if owner.isPackageObject && ! isPrivate && name != nme.CONSTRUCTOR then
0 commit comments