From de012b3a6d04f1e7a9fd6fecd403e0492f6ad7c1 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 4 Nov 2010 00:06:52 +0000 Subject: Some minor patmat/symbols cleanups, some of whi... Some minor patmat/symbols cleanups, some of which I could swear I'd already checked in. No review. --- src/compiler/scala/tools/nsc/matching/MatchSupport.scala | 3 +++ src/compiler/scala/tools/nsc/matching/PatternBindings.scala | 9 +-------- src/compiler/scala/tools/nsc/symtab/Symbols.scala | 10 +++++----- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/compiler/scala/tools/nsc/matching/MatchSupport.scala b/src/compiler/scala/tools/nsc/matching/MatchSupport.scala index 2f50435db6..7cd8a27d3e 100644 --- a/src/compiler/scala/tools/nsc/matching/MatchSupport.scala +++ b/src/compiler/scala/tools/nsc/matching/MatchSupport.scala @@ -23,6 +23,9 @@ trait MatchSupport extends ast.TreeDSL { self: ParallelMatching => def impossible: Nothing = abort("this never happens") + def treeCollect[T](tree: Tree, pf: PartialFunction[Tree, T]): List[T] = + tree filter (pf isDefinedAt _) map (x => pf(x)) + object Types { import definitions._ implicit def enrichType(x: Type): RichType = new RichType(x) diff --git a/src/compiler/scala/tools/nsc/matching/PatternBindings.scala b/src/compiler/scala/tools/nsc/matching/PatternBindings.scala index 83fd3a9608..61ab4f31d1 100644 --- a/src/compiler/scala/tools/nsc/matching/PatternBindings.scala +++ b/src/compiler/scala/tools/nsc/matching/PatternBindings.scala @@ -119,17 +119,10 @@ trait PatternBindings extends ast.TreeDSL case _ => Nil } private def deepstrip(t: Tree): List[Symbol] = - t filter { case _: Bind => true ; case _ => false } map (_.symbol) + treeCollect(t, { case x: Bind => x.symbol }) } case class Binding(pvar: Symbol, tvar: Symbol) { - // see bug #1843 for the consequences of not setting info. - // there is surely a better way to do this, especially since - // this looks to be the only usage of containsTp anywhere - // in the compiler, but it suffices for now. - if (tvar.info containsTp WildcardType) - tvar setInfo pvar.info - override def toString() = pp(pvar -> tvar) } diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 7ffc168c6e..9bf59d0bfc 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -376,12 +376,12 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => final def isPackageObject = isModule && name == nme.PACKAGEkw && owner.isPackageClass final def isPackageObjectClass = isModuleClass && name.toTermName == nme.PACKAGEkw && owner.isPackageClass final def definedInPackage = owner.isPackageClass || owner.isPackageObjectClass - final def isPredefModule = isModule && name == nme.Predef && owner.isScalaPackageClass // not printed as a prefix + final def isPredefModule = this == PredefModule // not printed as a prefix final def isJavaInterface = isJavaDefined && isTrait - final def isScalaPackage = isPackage && name == nme.scala_ && owner.isRoot || // not printed as a prefix - isPackageObject && owner.isScalaPackageClass - final def isScalaPackageClass: Boolean = isPackageClass && owner.isRoot && name == nme.scala_.toTypeName || - isPackageObjectClass && owner.isScalaPackageClass // not printed as a prefix + + // not printed as prefixes + final def isScalaPackage = (this == ScalaPackage) || (isPackageObject && owner == ScalaPackageClass) + final def isScalaPackageClass = (this == ScalaPackageClass) || (isPackageObjectClass && owner == ScalaPackageClass) /** Is symbol a monomorphic type? * assumption: if a type starts out as monomorphic, it will not acquire -- cgit v1.2.3