diff options
author | Martin Odersky <odersky@gmail.com> | 2013-11-15 19:33:18 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-11-15 19:33:18 +0100 |
commit | 3d01335c750de022e87914f44e017051abac290f (patch) | |
tree | ee97f48087be9fcf4298139a05ca0093a39ccc06 /src/dotty/tools/dotc/core/Types.scala | |
parent | 6ca5d414e729a509a00ddc508f2abf3d24da56ca (diff) | |
download | dotty-3d01335c750de022e87914f44e017051abac290f.tar.gz dotty-3d01335c750de022e87914f44e017051abac290f.tar.bz2 dotty-3d01335c750de022e87914f44e017051abac290f.zip |
Converting most uses of NamedType to select.
Select reduces refinetype/typeref pairs and is therefore preferable over raw NamedType.
Still need to do the same for TypeRefs.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 2cb14bf8f..d6dc81d4e 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -679,17 +679,31 @@ object Types { } /** The type <this . name> , reduced if possible */ - def select(name: Name)(implicit ctx: Context): Type = { - val res = lookupRefined(this, name) - if (res.exists) res else NamedType(this, name) + def select(name: Name)(implicit ctx: Context): Type = name match { + case name: TermName => + TermRef(this, name) + case name: TypeName => + val res = lookupRefined(this, name) + if (res.exists) res else TypeRef(this, name) } - /** The type <this . name> with given symbol, reduced if possible */ - def select(sym: Symbol)(implicit ctx: Context): Type = { - val res = lookupRefined(this, sym.name) - if (res.exists) res else NamedType.withSym(this, sym) + /** The type <this . name> , reduced if possible, with given denotation if undreduced */ + def select(name: Name, denot: Denotation)(implicit ctx: Context): Type = name match { + case name: TermName => + TermRef(this, name).withDenot(denot) + case name: TypeName => + val res = lookupRefined(this, name) + if (res.exists) res else TypeRef(this, name).withDenot(denot) } + /** The type <this . name> with given symbol, reduced if possible */ + def select(sym: Symbol)(implicit ctx: Context): Type = + if (sym.isTerm) TermRef.withSym(this, sym.asTerm) + else { + val res = lookupRefined(this, sym.name) + if (res.exists) res else TypeRef.withSym(this, sym.asType) + } + protected def lookupRefined(pre: Type, name: Name)(implicit ctx: Context): Type = pre.stripTypeVar match { case pre: RefinedType => if (pre.refinedName ne name) lookupRefined(pre.parent, name) @@ -1551,9 +1565,6 @@ object Types { def apply(prefix: Type, name: Name)(implicit ctx: Context) = if (name.isTermName) TermRef(prefix, name.asTermName) else TypeRef(prefix, name.asTypeName) - def withSym(prefix: Type, sym: Symbol)(implicit ctx: Context) = - if (sym.isTerm) TermRef.withSym(prefix, sym.asTerm) - else TypeRef.withSym(prefix, sym.asType) } object TermRef { |