diff options
author | Paul Phillips <paulp@improving.org> | 2012-10-23 14:42:36 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-10-23 14:51:09 -0700 |
commit | 56b23776f14499e96078be403a423f23ba50dbbb (patch) | |
tree | ffe3ba943d98f5dc4c814b298c3cce6e62da669f /src | |
parent | d477a0f7f90d224f8162abd9847ecf71482e179a (diff) | |
download | scala-56b23776f14499e96078be403a423f23ba50dbbb.tar.gz scala-56b23776f14499e96078be403a423f23ba50dbbb.tar.bz2 scala-56b23776f14499e96078be403a423f23ba50dbbb.zip |
Made SilentResult more monadic.
Given that it's just a reimplementation of Option, we may as
well not also reimplement methods like map and getOrElse at
every call site.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 2c3ff0bfa4..d0c4d6d65f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -68,7 +68,20 @@ trait Typers extends Modes with Adaptations with Tags { } */ - sealed abstract class SilentResult[+T] + sealed abstract class SilentResult[+T] { + @inline final def map[U](f: T => U): SilentResult[U] = this match { + case SilentResultValue(value) => SilentResultValue(f(value)) + case x: SilentTypeError => x + } + @inline final def filter(p: T => Boolean): SilentResult[T] = this match { + case SilentResultValue(value) if !p(value) => SilentTypeError(TypeErrorWrapper(new TypeError(NoPosition, "!p"))) + case _ => this + } + @inline final def orElse[T1 >: T](f: AbsTypeError => T1): T1 = this match { + case SilentResultValue(value) => value + case SilentTypeError(err) => f(err) + } + } case class SilentTypeError(err: AbsTypeError) extends SilentResult[Nothing] { } case class SilentResultValue[+T](value: T) extends SilentResult[T] { } |