summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2011-10-20 22:28:35 +0000
committerAdriaan Moors <adriaan.moors@epfl.ch>2011-10-20 22:28:35 +0000
commit612f87b3d3ed214ca2f1753de923720fd2948aee (patch)
treecb2f0ded809b96bbf240f5fff45bd3dd3e2d98e5
parent0816035d762b428f5c1698765c4709014a0ba3bd (diff)
downloadscala-612f87b3d3ed214ca2f1753de923720fd2948aee.tar.gz
scala-612f87b3d3ed214ca2f1753de923720fd2948aee.tar.bz2
scala-612f87b3d3ed214ca2f1753de923720fd2948aee.zip
eternalized Paul's findings wrt thisSym
-rw-r--r--src/compiler/scala/reflect/internal/Symbols.scala22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala
index 8175040a76..bd9164cfc4 100644
--- a/src/compiler/scala/reflect/internal/Symbols.scala
+++ b/src/compiler/scala/reflect/internal/Symbols.scala
@@ -1288,8 +1288,26 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
c
}
- /** The self symbol of a class with explicit self type, or else the
- * symbol itself.
+ /** The self symbol (a TermSymbol) of a class with explicit self type, or else the
+ * symbol itself (a TypeSymbol).
+ *
+ * WARNING: you're probably better off using typeOfThis, as it's more uniform across classes with and without self variables.
+ *
+ * Example by Paul:
+ * scala> trait Foo1 { }
+ * scala> trait Foo2 { self => }
+ * scala> intp("Foo1").thisSym
+ * res0: $r.intp.global.Symbol = trait Foo1
+ *
+ * scala> intp("Foo2").thisSym
+ * res1: $r.intp.global.Symbol = value self
+ *
+ * Martin says: The reason `thisSym' is `this' is so that thisType can be this.thisSym.tpe.
+ * It's a trick to shave some cycles off.
+ *
+ * Morale: DO: if (clazz.typeOfThis.typeConstructor ne clazz.typeConstructor) ...
+ * DON'T: if (clazz.thisSym ne clazz) ...
+ *
*/
def thisSym: Symbol = this