diff options
author | Martin Odersky <odersky@gmail.com> | 2016-09-13 18:12:15 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-10-02 16:12:28 +0200 |
commit | 84bc770bb7bcac2fe09a13c62c24aac1e3fda582 (patch) | |
tree | 9b69b8bc96193e14df75468f2df4e2c50ff7ccc5 | |
parent | 65551d19b5d928f231426c016e561051d68d9c97 (diff) | |
download | dotty-84bc770bb7bcac2fe09a13c62c24aac1e3fda582.tar.gz dotty-84bc770bb7bcac2fe09a13c62c24aac1e3fda582.tar.bz2 dotty-84bc770bb7bcac2fe09a13c62c24aac1e3fda582.zip |
Drop annotations from dealias
We got an error when we tried t opur @inline annotations
on function parameter types. It turned out that there were
lots of places where annotations on a type would break a test
in the compiler.
So we now drop annotations by default when dealiasing. We provide
dealiasKeepAnnots as an alternative that has the old behavior, i.e.
rewrap annotations after dealiasing. The only place where we found we
needed this was in the exhaustivity checker.
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 32 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/patmat/Space.scala | 2 |
2 files changed, 23 insertions, 11 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 0c9a12701..00286156a 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -848,30 +848,42 @@ object Types { case tp => tp } - /** Follow aliases and dereferences LazyRefs and instantiated TypeVars until type - * is no longer alias type, LazyRef, or instantiated type variable. - */ - final def dealias(implicit ctx: Context): Type = this match { + private def dealias(keepAnnots: Boolean)(implicit ctx: Context): Type = this match { case tp: TypeRef => if (tp.symbol.isClass) tp else tp.info match { - case TypeAlias(tp) => tp.dealias + case TypeAlias(tp) => tp.dealias(keepAnnots) case _ => tp } case tp: TypeVar => val tp1 = tp.instanceOpt - if (tp1.exists) tp1.dealias else tp + if (tp1.exists) tp1.dealias(keepAnnots) else tp case tp: AnnotatedType => - tp.derivedAnnotatedType(tp.tpe.dealias, tp.annot) + val tp1 = tp.tpe.dealias(keepAnnots) + if (keepAnnots) tp.derivedAnnotatedType(tp1, tp.annot) else tp1 case tp: LazyRef => - tp.ref.dealias + tp.ref.dealias(keepAnnots) case app @ HKApply(tycon, args) => - val tycon1 = tycon.dealias - if (tycon1 ne tycon) app.superType.dealias + val tycon1 = tycon.dealias(keepAnnots) + if (tycon1 ne tycon) app.superType.dealias(keepAnnots) else this case _ => this } + /** Follow aliases and dereferences LazyRefs and instantiated TypeVars until type + * is no longer alias type, LazyRef, or instantiated type variable. + * Goes through annotated types and rewraps annotations on the result. + */ + final def dealiasKeepAnnots(implicit ctx: Context): Type = + dealias(keepAnnots = true) + + /** Follow aliases and dereferences LazyRefs, annotated types and instantiated + * TypeVars until type is no longer alias type, annotated type, LazyRef, + * or instantiated type variable. + */ + final def dealias(implicit ctx: Context): Type = + dealias(keepAnnots = false) + /** Perform successive widenings and dealiasings until none can be applied anymore */ final def widenDealias(implicit ctx: Context): Type = { val res = this.widen.dealias diff --git a/src/dotty/tools/dotc/transform/patmat/Space.scala b/src/dotty/tools/dotc/transform/patmat/Space.scala index d942c6853..830d0f938 100644 --- a/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -522,7 +522,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { } val Match(sel, cases) = tree - isCheckable(sel.tpe.widen.deAnonymize.dealias) + isCheckable(sel.tpe.widen.deAnonymize.dealiasKeepAnnots) } |