From b3d0902d2219f9680180b17ff7f0b22aa11aae90 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 22 Jul 2013 15:58:46 +0200 Subject: 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. --- src/dotty/tools/dotc/core/Types.scala | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/dotty/tools/dotc/core/Types.scala') 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 */ -- cgit v1.2.3