From a19237f7be972870ca1c7477704a724419ef793f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 25 Dec 2013 15:59:02 +0100 Subject: Making the name of self visible inside a class. Previously, it wasn't. --- src/dotty/tools/dotc/typer/Namer.scala | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/dotty/tools/dotc/typer') diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 2baa3ea13..25006d72f 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -34,8 +34,14 @@ trait NamerContextOps { this: Context => /** The denotation with the given name in current context */ def denotNamed(name: Name): Denotation = if (owner.isClass) - if (outer.owner == owner) + if (outer.owner == owner) { // inner class scope; check whether we are referring to self + if (scope.size == 1) { + val elem = scope.asInstanceOf[MutableScope].lastEntry + if (elem.name == name) return elem.sym.denot // return self + } + assert(scope.size <= 1, scope) owner.thisType.member(name) + } else // we are in the outermost context belonging to a class; self is invisible here. See inClassContext. owner.findMember(name, owner.thisType, EmptyFlags) else -- cgit v1.2.3