Skip to content

Commit 873e423

Browse files
committed
More comments and drop debug statement
1 parent 2256ca5 commit 873e423

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

+9-6
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ class Namer { typer: Typer =>
302302

303303
typr.println(i"creating symbol for $tree in ${ctx.mode}")
304304

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+
*/
305311
def checkNoConflict(name: Name, isPrivate: Boolean): Name =
306312
val owner = ctx.owner
307313
var conflictsDetected = false
@@ -315,23 +321,20 @@ class Namer { typer: Typer =>
315321
conflictsDetected = true
316322

317323
def checkNoConflictWith(preExisting: Symbol) =
324+
val preExisting = owner.unforcedDecls.lookup(name)
318325
if (preExisting.isDefinedInCurrentRun || preExisting.lastKnownDenotation.is(Package))
319326
&& (!preExisting.lastKnownDenotation.is(Private) || preExisting.owner.is(Package))
320327
then conflict(preExisting)
321328

322-
def checkNoConflictIn(owner: Symbol) =
323-
checkNoConflictWith( owner.unforcedDecls.lookup(name))
324-
325329
def pkgObjs(pkg: Symbol) =
326330
pkg.denot.asInstanceOf[PackageClassDenotation].packageObjs.map(_.symbol)
327331

328-
def preExisting = ctx.effectiveScope.lookup(name)
329332
if owner.is(PackageClass) then
330-
checkNoConflictWith(preExisting)
331-
return name
333+
checkNoConflictIn(owner)
332334
for pkgObj <- pkgObjs(owner) do
333335
checkNoConflictIn(pkgObj)
334336
else
337+
def preExisting = ctx.effectiveScope.lookup(name)
335338
if (!owner.isClass || name.isTypeName) && preExisting.exists then
336339
conflict(preExisting)
337340
else if owner.isPackageObject && !isPrivate && name != nme.CONSTRUCTOR then

0 commit comments

Comments
 (0)