aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/SymDenotations.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-10-07 09:21:06 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2014-10-12 10:50:00 +0200
commit0e6e7bebaccf08796c578ae58c99d0bd5a2336d2 (patch)
treeb22b9f2d4de7c25fdb9f54dbf8c7a77a6a5126f6 /src/dotty/tools/dotc/core/SymDenotations.scala
parentf0578aa4bd3c87bd00658f4138eef3e4624f035e (diff)
downloaddotty-0e6e7bebaccf08796c578ae58c99d0bd5a2336d2.tar.gz
dotty-0e6e7bebaccf08796c578ae58c99d0bd5a2336d2.tar.bz2
dotty-0e6e7bebaccf08796c578ae58c99d0bd5a2336d2.zip
Re-usable method to determine self-ness.
Method isSelfSym decides whether a symbol is the symbol of a self definition in a class. Also, make all self symbols private[this]
Diffstat (limited to 'src/dotty/tools/dotc/core/SymDenotations.scala')
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala
index da83811f1..ae37ab87c 100644
--- a/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -43,14 +43,10 @@ trait SymDenotations { this: Context =>
if (denot is ValidForever) true
else try {
val owner = denot.owner.denot
- def isSelfSym = owner.infoOrCompleter match {
- case ClassInfo(_, _, _, _, selfInfo) => selfInfo == denot.symbol
- case _ => false
- }
stillValid(owner) && (
!owner.isClass
|| (owner.decls.lookupAll(denot.name) contains denot.symbol)
- || isSelfSym
+ || denot.isSelfSym
)
} catch {
case ex: StaleSymbol => false
@@ -360,6 +356,23 @@ object SymDenotations {
/** Is this symbol an abstract or alias type? */
final def isAbstractOrAliasType = isType & !isClass
+ /** Is this the denotation of a self symbol of some class?
+ * This is the case if one of two conditions holds:
+ * 1. It is the symbol referred to in the selfInfo part of the ClassInfo
+ * which is the type of this symbol's owner.
+ * 2. This symbol is owned by a class, it's selfInfo field refers to a type
+ * (indicating the self definition does not introduce a name), and the
+ * symbol's name is "_".
+ * TODO: Find a more robust way to characterize self symbols, maybe by
+ * spending a Flag on them?
+ */
+ final def isSelfSym(implicit ctx: Context) = owner.infoOrCompleter match {
+ case ClassInfo(_, _, _, _, selfInfo) =>
+ selfInfo == symbol ||
+ selfInfo.isInstanceOf[Type] && name == nme.WILDCARD
+ case _ => false
+ }
+
/** Is this definition contained in `boundary`?
* Same as `ownersIterator contains boundary` but more efficient.
*/