From f4dab01c5e85897349830210df1b4e074e0b24ee Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 16 Dec 2013 12:29:25 +0100 Subject: Check for no double defs Added check for double def if owner of scope is not a class. For class members we will need a more refined check. One way to do it is to immediately rule out doubly defined members with same signature. --- src/dotty/tools/dotc/typer/Namer.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 9eefec624..4ea87bb7b 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -185,11 +185,14 @@ class Namer { typer: Typer => def enterSymbol(sym: Symbol)(implicit ctx: Context) = { if (sym.exists) { println(s"entered: $sym in ${ctx.owner} and ${ctx.effectiveScope}") + def preExisting = ctx.effectiveScope.lookup(sym.name) if (sym.owner is PackageClass) { - val preExisting = sym.owner.decls.lookup(sym.name) if (preExisting.isDefinedInCurrentRun) ctx.error(s"${sym.showLocated} is compiled twice", sym.pos) } + else if (!sym.owner.isClass && preExisting.exists) { + ctx.error(i"${sym.name} is already defined as $preExisting") + } ctx.enter(sym) } sym -- cgit v1.2.3