summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2012-04-27 17:11:36 +0200
committerAdriaan Moors <adriaan.moors@epfl.ch>2012-05-02 12:30:28 +0200
commitf004e99b2fb7450fbfd0c5d96a4b2406cb8fc142 (patch)
tree69e52be0bd8f9b823768daed95c0169acbea8df0
parent90d2bee45b25844f809f8c5300aefcb1bfe9e336 (diff)
downloadscala-f004e99b2fb7450fbfd0c5d96a4b2406cb8fc142.tar.gz
scala-f004e99b2fb7450fbfd0c5d96a4b2406cb8fc142.tar.bz2
scala-f004e99b2fb7450fbfd0c5d96a4b2406cb8fc142.zip
small tree attachment refactoring: firstAttachment
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala3
-rw-r--r--src/library/scala/reflect/api/Trees.scala11
2 files changed, 7 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 41b896eb93..2410117af7 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -2209,7 +2209,8 @@ trait Typers extends Modes with Adaptations with Taggings with PatMatVirtualiser
def adaptCase(cdef: CaseDef, mode: Int, tpe: Type): CaseDef = deriveCaseDef(cdef)(adapt(_, mode, tpe))
// takes untyped sub-trees of a match and type checks them
- def typedMatch(selector0: Tree, cases: List[CaseDef], mode: Int, resTp: Type) = {
+ def typedMatch(selector0: Tree, cases: List[CaseDef], mode: Int, resTp: Type): Match = {
+ // strip off the annotation as it won't type check
val (selector, doTranslation) = selector0 match {
case Annotated(Ident(nme.synthSwitch), selector) => (selector, false)
case s => (s, true)
diff --git a/src/library/scala/reflect/api/Trees.scala b/src/library/scala/reflect/api/Trees.scala
index f1e9cc13ca..b82972c9bc 100644
--- a/src/library/scala/reflect/api/Trees.scala
+++ b/src/library/scala/reflect/api/Trees.scala
@@ -110,13 +110,12 @@ trait Trees { self: Universe =>
def withoutAttachment(att: Any): this.type = { detach(att); this }
def attachment[T: ClassTag]: T = attachmentOpt[T] getOrElse { throw new Error("no attachment of type %s".format(classTag[T].erasure)) }
def attachmentOpt[T: ClassTag]: Option[T] =
+ firstAttachment { case attachment if attachment.getClass == classTag[T].erasure => attachment.asInstanceOf[T] }
+
+ def firstAttachment[T](p: PartialFunction[Any, T]): Option[T] =
rawatt match {
- case NontrivialAttachment(pos, payload) =>
- val index = payload.indexWhere(p => p.getClass == classTag[T].erasure)
- if (index != -1) Some(payload(index).asInstanceOf[T])
- else None
- case _ =>
- None
+ case NontrivialAttachment(pos, payload) => payload.collectFirst(p)
+ case _ => None
}
private[this] var rawtpe: Type = _