diff options
author | Martin Odersky <odersky@gmail.com> | 2014-04-03 17:55:20 +0200 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-04-08 17:02:29 +0200 |
commit | d079c0291289ad9f6517b0b929c4f03ef6b9f082 (patch) | |
tree | 0a6fdfd3b6d5409228716c84d32a7fb2df9c5ee1 /src/dotty/tools/dotc/typer/Checking.scala | |
parent | 09a4bc5d099de71de824a35a67a26e7091e3bb5a (diff) | |
download | dotty-d079c0291289ad9f6517b0b929c4f03ef6b9f082.tar.gz dotty-d079c0291289ad9f6517b0b929c4f03ef6b9f082.tar.bz2 dotty-d079c0291289ad9f6517b0b929c4f03ef6b9f082.zip |
Flag self names that conflict with parameters or members
A self name may no longer have the same name as a parameterless
class member (or param accessor). The restriction makes sense because
otherwise scoping is confusing. It's needed because otherwise we get
TermRefs that have the same name and prefix but denote different things.
Moved some code which exercises this from pos/typers to neg/typers
Diffstat (limited to 'src/dotty/tools/dotc/typer/Checking.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/Checking.scala | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala index 287e93c7a..ae325af2a 100644 --- a/src/dotty/tools/dotc/typer/Checking.scala +++ b/src/dotty/tools/dotc/typer/Checking.scala @@ -102,13 +102,14 @@ trait Checking { tp } - /** Check that class does not define */ + /** Check that class does not define same symbol twice */ def checkNoDoubleDefs(cls: Symbol)(implicit ctx: Context): Unit = { val seen = new mutable.HashMap[Name, List[Symbol]] { override def default(key: Name) = Nil } typr.println(i"check no double defs $cls") - for (decl <- cls.info.decls) { + + def checkDecl(decl: Symbol): Unit = { for (other <- seen(decl.name)) { typr.println(i"conflict? $decl $other") if (decl.signature matches other.signature) { @@ -129,6 +130,12 @@ trait Checking { } seen(decl.name) = decl :: seen(decl.name) } + + cls.info.decls.foreach(checkDecl) + cls.info match { + case ClassInfo(_, _, _, _, selfSym: Symbol) => checkDecl(selfSym) + case _ => + } } def checkInstantiatable(cls: ClassSymbol, pos: Position): Unit = { |