aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Types.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r--src/dotty/tools/dotc/core/Types.scala20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 624549bac..e0e9a535f 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -190,6 +190,16 @@ object Types {
def isRepeatedParam(implicit ctx: Context): Boolean =
typeSymbol eq defn.RepeatedParamClass
+ /** Does this type carry an UnsafeNonvariant annotation? */
+ final def isUnsafeNonvariant(implicit ctx: Context): Boolean = this match {
+ case AnnotatedType(_, annot) => annot.symbol == defn.UnsafeNonvariantAnnot
+ case _ => false
+ }
+
+ /** Does this type have an UnsafeNonvariant annotation on one of its parts? */
+ final def hasUnsafeNonvariant(implicit ctx: Context): Boolean =
+ new HasUnsafeNonAccumulator().apply(false, this)
+
/** Is this the type of a method that has a repeated parameter type as
* last parameter type?
*/
@@ -755,6 +765,12 @@ object Types {
case _ => this
}
+ /** If this is a skolem, its underlying type, otherwise the type itself */
+ final def widenSkolem(implicit ctx: Context): Type = this match {
+ case tp: SkolemType => tp.underlying
+ case _ => this
+ }
+
/** Follow aliases and dereferences LazyRefs and instantiated TypeVars until type
* is no longer alias type, LazyRef, or instantiated type variable.
*/
@@ -3239,6 +3255,10 @@ object Types {
def apply(x: Unit, tp: Type): Unit = foldOver(p(tp), tp)
}
+ class HasUnsafeNonAccumulator(implicit ctx: Context) extends TypeAccumulator[Boolean] {
+ def apply(x: Boolean, tp: Type) = x || tp.isUnsafeNonvariant || foldOver(x, tp)
+ }
+
class NamedPartsAccumulator(p: NamedType => Boolean)(implicit ctx: Context) extends TypeAccumulator[mutable.Set[NamedType]] {
override def stopAtStatic = false
def maybeAdd(x: mutable.Set[NamedType], tp: NamedType) = if (p(tp)) x += tp else x