diff options
author | Paul Phillips <paulp@improving.org> | 2010-12-23 16:13:00 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-12-23 16:13:00 +0000 |
commit | 932694494d556b2802d59e1e342b6036405d0407 (patch) | |
tree | d305d5d7df125e63b51dd6a134e05cb05661d149 | |
parent | 54f75dc98f07ba02a17e4cd7b4117468518c115c (diff) | |
download | scala-932694494d556b2802d59e1e342b6036405d0407.tar.gz scala-932694494d556b2802d59e1e342b6036405d0407.tar.bz2 scala-932694494d556b2802d59e1e342b6036405d0407.zip |
A pretty severe cleanup of typeRef.
stay for the aesthetics! Review by odersky.
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Types.scala | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index ad1cf598b6..5f5c1bfb90 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -2644,43 +2644,32 @@ A type's typeSymbol should never be inspected directly. * todo: see how we can clean this up a bit */ def typeRef(pre: Type, sym: Symbol, args: List[Type]): Type = { - def rebindTR(pre: Type, sym: Symbol): Symbol = { - if(sym.isAbstractType) rebind(pre, sym) else sym - // type alias selections are rebound in TypeMap ("coevolved", actually -- see #3731) - // e.g., when type parameters that are referenced by the alias are instantiated in the prefix - // see pos/depmet_rebind_typealias - } - val sym1 = rebindTR(pre, sym) + // type alias selections are rebound in TypeMap ("coevolved", actually -- see #3731) + // e.g., when type parameters that are referenced by the alias are instantiated in + // the prefix. See pos/depmet_rebind_typealias. + def rebindTR(pre: Type, sym: Symbol) = + if (sym.isAbstractType) rebind(pre, sym) else sym - def transform(tp: Type): Type = - tp.resultType.asSeenFrom(pre, sym1.owner).instantiateTypeParams(sym1.typeParams, args) + val sym1 = rebindTR(pre, sym) + // we require that object is initialized, thus info.typeParams instead of typeParams. if (sym1.isAliasType && sameLength(sym1.info.typeParams, args)) { - if (!sym1.lockOK) - throw new TypeError("illegal cyclic reference involving " + sym1) - // note: we require that object is initialized, - // that's why we use info.typeParams instead of typeParams. -/* - sym1.lock { - throw new TypeError("illegal cyclic reference involving " + sym1) - } - transform(sym1.info) // check there are no cycles - sym1.unlock() -*/ - TypeRef(pre, sym1, args) // don't expand type alias (cycles checked above) - } else { + if (sym1.lockOK) TypeRef(pre, sym1, args) // don't expand type alias (cycles checked by lockOK) + else throw new TypeError("illegal cyclic reference involving " + sym1) + } + else { val pre1 = removeSuper(pre, sym1) - if (pre1 ne pre) { + if (pre1 ne pre) typeRef(pre1, rebindTR(pre1, sym1), args) - } - else if (sym1.isClass && pre.isInstanceOf[CompoundType]) { - // sharpen prefix so that it is maximal and still contains the class. - var p = pre.parents.reverse - while (!p.isEmpty && p.head.member(sym1.name) != sym1) p = p.tail - if (p.isEmpty) TypeRef(pre, sym1, args) - else typeRef(p.head, sym1, args) - } else { - TypeRef(pre, sym1, args) + else pre match { + case _: CompoundType if sym1.isClass => + // sharpen prefix so that it is maximal and still contains the class. + pre.parents.reverse dropWhile (_.member(sym1.name) != sym1) match { + case Nil => TypeRef(pre, sym1, args) + case parent :: _ => typeRef(parent, sym1, args) + } + case _ => + TypeRef(pre, sym1, args) } } } |