diff options
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 */ |