diff options
author | Martin Odersky <odersky@gmail.com> | 2013-07-22 15:58:46 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-07-22 15:58:46 +0200 |
commit | b3d0902d2219f9680180b17ff7f0b22aa11aae90 (patch) | |
tree | 7885e42fe18e6744e34531a2f63dd7eaf61b0f3d /src/dotty/tools/dotc/core | |
parent | 4b265ca213d066897db3a2333a3ac1420e8a480f (diff) | |
download | dotty-b3d0902d2219f9680180b17ff7f0b22aa11aae90.tar.gz dotty-b3d0902d2219f9680180b17ff7f0b22aa11aae90.tar.bz2 dotty-b3d0902d2219f9680180b17ff7f0b22aa11aae90.zip |
SeqLiteral refactoring
SeqLiterals no longer have an elemtpt subtree. Their type is now no longer a RepeatedParamType, but instead an instance of SeqType or ArrayType.
Diffstat (limited to 'src/dotty/tools/dotc/core')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 19 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/UnPickler.scala | 5 |
2 files changed, 22 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 26886ed1d..af2b694f5 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -648,6 +648,10 @@ object Types { Set((Set(), Set())) } + /** The element type of a sequence or array */ + def elemType(implicit ctx: Context): Type = + firstBaseTypeArg(defn.SeqClass) orElse firstBaseTypeArg(defn.ArrayClass) + // ----- Substitutions ----------------------------------------------------- /** Substitute all types that refer in their symbol attribute to @@ -742,6 +746,21 @@ object Types { else TypeAlias(this) } + /** The type arguments of the base type instance wrt `base` of this type */ + final def baseTypeArgs(base: Symbol)(implicit ctx: Context): List[Type] = + if (this <:< base.symRef) + base.typeParams map (param => member(param.name).info.argType(param)) + else + Nil + + /** The first type argument of the base type instance wrt `base` of this type */ + final def firstBaseTypeArg(base: Symbol)(implicit ctx: Context): Type = base.typeParams match { + case param :: _ if this <:< base.symRef => + member(param.name).info.argType(param) + case _ => + NoType + } + /** If this is an encoding of a (partially) applied type, return its arguments, * otherwise return Nil */ diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala index 3b9ca7ba5..70798ad8a 100644 --- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala +++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala @@ -780,7 +780,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: val end = readNat() + readIndex // array elements are trees representing instances of scala.annotation.Annotation SeqLiteral( - TypeTree(defn.AnnotationClass.typeConstructor), + defn.SeqType.appliedTo(defn.AnnotationClass.typeConstructor :: Nil), until(end, () => readClassfileAnnotArg(readNat()))) } @@ -983,7 +983,8 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: case ARRAYVALUEtree => val elemtpt = readTreeRef() val trees = until(end, readTreeRef) - SeqLiteral(elemtpt, trees) + SeqLiteral(defn.SeqType.appliedTo(elemtpt.tpe :: Nil), trees) + // note can't deal with trees passed to Java methods as arrays here case FUNCTIONtree => setSym() |