From fe8280c020eab60a7f94cb1faa50ba412635caea Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 23 Apr 2013 07:30:37 -0700 Subject: Added orElse to Type. Tree and Symbol each have the analogous method, so consistency calls along with utility for putting it on Type. --- src/reflect/scala/reflect/api/Types.scala | 6 ++++++ src/reflect/scala/reflect/internal/Types.scala | 2 ++ 2 files changed, 8 insertions(+) (limited to 'src') diff --git a/src/reflect/scala/reflect/api/Types.scala b/src/reflect/scala/reflect/api/Types.scala index 1152f97350..0291d5d26f 100644 --- a/src/reflect/scala/reflect/api/Types.scala +++ b/src/reflect/scala/reflect/api/Types.scala @@ -209,6 +209,12 @@ trait Types { /******************* helpers *******************/ + /** Provides an alternate if type is NoType. + * + * @group Helpers + */ + def orElse(alt: => Type): Type + /** Substitute symbols in `to` for corresponding occurrences of references to * symbols `from` in this type. */ diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index cd41f533bb..86115e7174 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -742,6 +742,8 @@ trait Types def map[T](f: Type => T): List[T] = collect(Type.this) map f } + @inline final def orElse(alt: => Type): Type = if (this ne NoType) this else alt + /** Returns optionally first type (in a preorder traversal) which satisfies predicate `p`, * or None if none exists. */ -- cgit v1.2.3