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/Types.scala | |
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/Types.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 19 |
1 files changed, 19 insertions, 0 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 */ |