aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Types.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-08-19 16:19:03 +0200
committerMartin Odersky <odersky@gmail.com>2013-08-19 16:19:03 +0200
commit62131749d08657a0103c922c626a0b918cf385b5 (patch)
treee8c49a9bb6eb41f3f5d4e3ca7e75a431a25c33b9 /src/dotty/tools/dotc/core/Types.scala
parentedb9facac55f61540e0f9af8d06ac9390830fcb8 (diff)
downloaddotty-62131749d08657a0103c922c626a0b918cf385b5.tar.gz
dotty-62131749d08657a0103c922c626a0b918cf385b5.tar.bz2
dotty-62131749d08657a0103c922c626a0b918cf385b5.zip
Several fixes and refactorings for typechecking
1) Refactoring of package loaders that ensures that a package is always loaded before new members are entered. This led to a refactoring of sourceModule in completers into its own trait 2) Refactoring of optSelfType ot selfInfo. Class Infos may now have a reference to a symbol in their selfInfo field, instead of always a type, as it was before. This allows to introduce laziness for self type evaluation. Laziness is needed so that modules can be desugared and the desugared version be compiled without special tricks. 3) <init> and $init members are no longer inherited. 4) Refactoring of createSymbol and enterSym, so that creating symbols and entering them in a scope is decoupled. Renamed the driver operation form `enterSym(s)` to `index`.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r--src/dotty/tools/dotc/core/Types.scala29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index cf756859f..1bc8f1646 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -1774,17 +1774,22 @@ object Types {
* These are all normalized to be TypeRefs by moving any refinements
* to be member definitions of the class itself.
* @param decls The symbols defined directly in this class.
- * @param optSelfType The type of `this` in this class, if explicitly given, NoType otherwise.
+ * @param selfInfo The type of `this` in this class, if explicitly given,
+ * NoType otherwise. If class is compiled from source, can also
+ * be a reference to the self symbol containing the type.
*/
abstract case class ClassInfo(
prefix: Type,
cls: ClassSymbol,
classParents: List[TypeRef],
decls: Scope,
- optSelfType: Type) extends CachedGroundType with TypeType {
+ selfInfo: DotClass /* should be: Type | Symbol */) extends CachedGroundType with TypeType {
- def selfType(implicit ctx: Context): Type =
- if (optSelfType.exists) optSelfType else cls.typeConstructor
+ def selfType(implicit ctx: Context): Type = selfInfo match {
+ case NoType => cls.typeConstructor
+ case self: Symbol => self.info
+ case tp: Type => tp
+ }
def rebase(tp: Type)(implicit ctx: Context): Type =
if ((prefix eq cls.owner.thisType) || !cls.owner.isClass) tp
@@ -1812,21 +1817,21 @@ object Types {
def derivedClassInfo(prefix: Type)(implicit ctx: Context) =
if (prefix eq this.prefix) this
- else ClassInfo(prefix, cls, classParents, decls, optSelfType)
+ else ClassInfo(prefix, cls, classParents, decls, selfInfo)
- def derivedClassInfo(prefix: Type, classParents: List[TypeRef], optSelfType: Type)(implicit ctx: Context) =
- if ((prefix eq this.prefix) && (classParents eq this.classParents) && (optSelfType eq this.optSelfType)) this
- else ClassInfo(prefix, cls, classParents, decls, optSelfType)
+ def derivedClassInfo(prefix: Type, classParents: List[TypeRef], selfInfo: Type)(implicit ctx: Context) =
+ if ((prefix eq this.prefix) && (classParents eq this.classParents) && (selfInfo eq this.selfInfo)) this
+ else ClassInfo(prefix, cls, classParents, decls, selfInfo)
override def computeHash = doHash(cls, prefix)
}
- final class CachedClassInfo(prefix: Type, cls: ClassSymbol, classParents: List[TypeRef], decls: Scope, optSelfType: Type)
- extends ClassInfo(prefix, cls, classParents, decls, optSelfType)
+ final class CachedClassInfo(prefix: Type, cls: ClassSymbol, classParents: List[TypeRef], decls: Scope, selfInfo: DotClass)
+ extends ClassInfo(prefix, cls, classParents, decls, selfInfo)
object ClassInfo {
- def apply(prefix: Type, cls: ClassSymbol, classParents: List[TypeRef], decls: Scope, optSelfType: Type = NoType)(implicit ctx: Context) =
- unique(new CachedClassInfo(prefix, cls, classParents, decls, optSelfType))
+ def apply(prefix: Type, cls: ClassSymbol, classParents: List[TypeRef], decls: Scope, selfInfo: DotClass = NoType)(implicit ctx: Context) =
+ unique(new CachedClassInfo(prefix, cls, classParents, decls, selfInfo))
}
/** Type bounds >: lo <: hi */