summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2007-07-23 18:07:57 +0000
committermichelou <michelou@epfl.ch>2007-07-23 18:07:57 +0000
commit2d3a640e0bff8c79f99c070cf33f9ef921642a18 (patch)
tree09e16ddea7a22fafb5e3c3fe4f19b8428235eba6 /src
parent11f1b34dde88cc4911e5d126c76c30c67a0b7cc2 (diff)
downloadscala-2d3a640e0bff8c79f99c070cf33f9ef921642a18.tar.gz
scala-2d3a640e0bff8c79f99c070cf33f9ef921642a18.tar.bz2
scala-2d3a640e0bff8c79f99c070cf33f9ef921642a18.zip
reverted 3 warning removals made in rev 12323 a...
reverted 3 warning removals made in rev 12323 and breaking patmatnew.scala
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/matching/ParallelMatching.scala234
-rw-r--r--src/compiler/scala/tools/nsc/matching/PatternMatchers.scala16
2 files changed, 126 insertions, 124 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
index fea443fdb7..9e478fe364 100644
--- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
+++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
@@ -22,25 +22,26 @@ trait ParallelMatching {
sealed trait RuleApplication
case class ErrorRule extends RuleApplication
- case class VariableRule(subst:List[Pair[Symbol,Symbol]], guard: Tree, body: Tree) extends RuleApplication
+ case class VariableRule(subst: List[Pair[Symbol,Symbol]], guard: Tree, body: Tree) extends RuleApplication
- def MixtureRule(scrutinee:Symbol, column:List[Tree], rest:Rep): RuleApplication = {
+ def MixtureRule(scrutinee: Symbol, column: List[Tree], rest: Rep): RuleApplication = {
def isSimpleIntSwitch: Boolean = {
(isSameType(scrutinee.tpe.widen, definitions.IntClass.tpe)/*||
isSameType(scrutinee.tpe.widen, definitions.CharClass.tpe)*/) && {
var xs = column
- while(!xs.isEmpty) { // forall
+ while (!xs.isEmpty) { // forall
val h = xs.head
- if(h.isInstanceOf[Literal] || isDefaultPattern(h)) { xs = xs.tail } else return false
+ if (h.isInstanceOf[Literal] || isDefaultPattern(h)) { xs = xs.tail } else return false
}
return true
}}
// an unapply for which we don't need a type test
def isUnapplyHead: Boolean = {
- def isUnapply(x:Tree): Boolean = x match {
- case Bind(_,p) => isUnapply(p)
- case UnApply(Apply(fn,_),arg) => fn.tpe match {
- case MethodType(List(argtpe,_*),_) =>
+ def isUnapply(x: Tree): Boolean = x match {
+ case Bind(_, p) =>
+ isUnapply(p)
+ case UnApply(Apply(fn,_), arg) => fn.tpe match {
+ case MethodType(List(argtpe,_*), _) =>
//Console.println("scrutinee.tpe"+scrutinee.tpe)
//Console.println("argtpe"+argtpe)
val r = scrutinee.tpe <:< argtpe
@@ -58,22 +59,22 @@ trait ParallelMatching {
}
// true if pattern type is direct subtype of scrutinee (can't use just <:< cause have to take variance into account)
- def directSubtype(ptpe:Type) =
+ def directSubtype(ptpe: Type) =
(ptpe.parents.exists { x => ((x.typeSymbol eq scrutinee.tpe.typeSymbol) && (x <:< scrutinee.tpe))});
// true if each pattern type is case and direct subtype of scrutinee
- def isFlatCases(col:List[Tree]): Boolean = (col eq Nil) || {
+ def isFlatCases(col: List[Tree]): Boolean = (col eq Nil) || {
strip2(col.head) match {
- case a @ Apply(fn,_) =>
- ((a.tpe.typeSymbol.flags & symtab.Flags.CASE) != 0) && directSubtype( a.tpe ) && isFlatCases(col.tail)
- case t @ Typed(_,tpt) =>
- ( (tpt.tpe.typeSymbol.flags & symtab.Flags.CASE) != 0) && directSubtype( t.tpe ) && isFlatCases(col.tail)
+ case a @ Apply(fn, _) =>
+ ((a.tpe.typeSymbol.flags & symtab.Flags.CASE) != 0) && directSubtype(a.tpe) && isFlatCases(col.tail)
+ case t @ Typed(_, tpt) =>
+ ( (tpt.tpe.typeSymbol.flags & symtab.Flags.CASE) != 0) && directSubtype(t.tpe) && isFlatCases(col.tail)
case Ident(nme.WILDCARD) =>
isFlatCases(col.tail) // treat col.tail specially?
case i @ Ident(n) => // n ne nme.WILDCARD
- ( (i.symbol.flags & symtab.Flags.CASE) != 0) && directSubtype( i.tpe ) && isFlatCases(col.tail)
- case s @ Select(_,_) => // i.e. scala.Nil
- ( (s.symbol.flags & symtab.Flags.CASE) != 0) && directSubtype( s.tpe ) && isFlatCases(col.tail)
+ ( (i.symbol.flags & symtab.Flags.CASE) != 0) && directSubtype(i.tpe) && isFlatCases(col.tail)
+ case s @ Select(_, _) => // i.e. scala.Nil
+ ( (s.symbol.flags & symtab.Flags.CASE) != 0) && directSubtype(s.tpe) && isFlatCases(col.tail)
case p =>
//Console.println(p.getClass)
false
@@ -81,19 +82,19 @@ trait ParallelMatching {
}
//def containsUnapply = column exists { _.isInstanceOf[UnApply] }
/*
- if(settings_debug) {
+ if (settings_debug) {
Console.println("/// MixtureRule("+scrutinee.name+":"+scrutinee.tpe+","+column+", rep = ")
Console.println(rest)
Console.println(")///")
}
*/
- if(isSimpleIntSwitch) {
+ if (isSimpleIntSwitch) {
//if(settings_debug) { Console.println("MixLiteral") }
return new MixLiterals(scrutinee, column, rest)
}
/*
- if((column.length > 1) && isFlatCases(column)) {
- if(settings_debug) {
+ if ((column.length > 1) && isFlatCases(column)) {
+ if (settings_debug) {
Console.println("flat cases!"+column)
Console.println(scrutinee.tpe.typeSymbol.children)
Console.println(scrutinee.tpe.member(nme.tag))
@@ -105,12 +106,12 @@ trait ParallelMatching {
}
*/
//Console.println("isUnapplyHead")
- if(isUnapplyHead) {
- if(settings_debug) { Console.println("MixUnapply") }
+ if (isUnapplyHead) {
+ if (settings_debug) { Console.println("MixUnapply") }
return new MixUnapply(scrutinee, column, rest)
}
- if(settings_debug) { Console.println("MixTypes") }
+ if (settings_debug) { Console.println("MixTypes") }
return new MixTypes(scrutinee, column, rest) // todo: handle type tests in unapply
}
@@ -121,12 +122,12 @@ trait ParallelMatching {
// e.g. (1,1) (1,3) (42,2) for column {case ..1.. => ;; case ..42..=> ;; case ..1.. => }
- protected var defaults: List[Int] = Nil
+ protected var defaults: List[Int] = Nil
var defaultV: collection.immutable.Set[Symbol] = emptySymbolSet
var theDefaultRows: List[Row] = null
def getDefaultRows: List[Row] = {
- if(theDefaultRows ne null)
+ if (theDefaultRows ne null)
return theDefaultRows
var res:List[Row] = Nil
var ds = defaults; while(ds ne Nil) {
@@ -138,8 +139,8 @@ trait ParallelMatching {
}
// sorted e.g. case _ => 7,5,1
- protected def insertDefault(tag: Int,vs:Set[Symbol]) {
- def ins(xs:List[Int]):List[Int] = xs match {
+ protected def insertDefault(tag: Int, vs: Set[Symbol]) {
+ def ins(xs: List[Int]): List[Int] = xs match {
case y::ys if y > tag => y::ins(ys)
case ys => tag :: ys
}
@@ -151,18 +152,18 @@ trait ParallelMatching {
var tagIndexPairs: TagIndexPair = null
protected def grabTemps: List[Symbol] = rest.temp
- protected def grabRow(index:Int): Row = rest.row(index)
+ protected def grabRow(index: Int): Row = rest.row(index)
/** inserts row indices using in to list of tagindexpairs*/
protected def tagIndicesToReps = {
val defaultRows = getDefaultRows
- var trs:List[(Int,Rep)] = Nil
+ var trs: List[(Int,Rep)] = Nil
var old = tagIndexPairs
- while(tagIndexPairs ne null) { // collect all with same tag
+ while (tagIndexPairs ne null) { // collect all with same tag
val tag = tagIndexPairs.tag
var tagRows = this.grabRow(tagIndexPairs.index)::Nil
tagIndexPairs = tagIndexPairs.next
- while((tagIndexPairs ne null) && tagIndexPairs.tag == tag) {
+ while ((tagIndexPairs ne null) && tagIndexPairs.tag == tag) {
tagRows = this.grabRow(tagIndexPairs.index)::tagRows
tagIndexPairs = tagIndexPairs.next
}
@@ -185,7 +186,7 @@ trait ParallelMatching {
* @return variables bound to default continuation,
* @return optionally, a default continuation,
**/
- def getTransition(implicit theOwner: Symbol): (List[(Int,Rep)],Set[Symbol],Option[Rep]) =
+ def getTransition(implicit theOwner: Symbol): (List[(Int,Rep)], Set[Symbol], Option[Rep]) =
(tagIndicesToReps, defaultV, {if(haveDefault) Some(defaultsToRep) else None})
}
@@ -194,25 +195,25 @@ trait ParallelMatching {
*
* this rule gets translated to a switch of _.$tag()
**/
- class MixCases(val scrutinee:Symbol, val column:List[Tree], val rest:Rep) extends CaseRuleApplication {
+ class MixCases(val scrutinee: Symbol, val column: List[Tree], val rest: Rep) extends CaseRuleApplication {
/** insert row indices using in to list of tagindexpairs */
{
var xs = column
- var i = 0
- while(xs ne Nil) { // forall
+ var i = 0
+ while (xs ne Nil) { // forall
val p = strip2(xs.head)
- if(isDefaultPattern(p))
- insertDefault(i,strip1(xs.head))
+ if (isDefaultPattern(p))
+ insertDefault(i, strip1(xs.head))
else
insertTagIndexPair(p.tpe.typeSymbol.tag, i)
- i = i + 1
+ i += 1
xs = xs.tail
}
}
override def grabTemps = scrutinee::rest.temp
- override def grabRow(index:Int) = rest.row(tagIndexPairs.index) match {
+ override def grabRow(index: Int) = rest.row(tagIndexPairs.index) match {
case Row(pats,s,g,b) => Row(column(tagIndexPairs.index)::pats,s,g,b)
}
@@ -243,17 +244,18 @@ trait ParallelMatching {
*
* this rule gets translated to a switch. all defaults/same literals are collected
**/
- class MixLiterals(val scrutinee:Symbol, val column:List[Tree], val rest:Rep) extends CaseRuleApplication {
+ class MixLiterals(val scrutinee: Symbol, val column: List[Tree], val rest: Rep) extends CaseRuleApplication {
- private var defaultIndexSet: Set64 = if(column.length < 64) new Set64 else null
+ private var defaultIndexSet: Set64 = if (column.length < 64) new Set64 else null
- override def insertDefault(tag: Int, vs: Set[Symbol]): Unit =
- if(defaultIndexSet eq null)
- super.insertDefault(tag,vs)
+ override def insertDefault(tag: Int, vs: Set[Symbol]) {
+ if (defaultIndexSet eq null)
+ super.insertDefault(tag, vs)
else {
defaultIndexSet |= tag
defaultV = defaultV ++ vs
}
+ }
protected override def haveDefault: Boolean =
((defaultIndexSet eq null) && super.haveDefault) | (defaultIndexSet.underlying != 0)
@@ -266,33 +268,33 @@ trait ParallelMatching {
super.getDefaultRows
else {
var ix = 63
- var res:List[Row] = Nil
- while((ix >= 0) && !defaultIndexSet.contains(ix)) { ix = ix - 1 }
- while(ix >= 0) {
+ var res: List[Row] = Nil
+ while ((ix >= 0) && !defaultIndexSet.contains(ix)) ix -= 1
+ while (ix >= 0) {
res = grabRow(ix) :: res
- ix = ix - 1
- while((ix >= 0) && !defaultIndexSet.contains(ix)) { ix = ix - 1 }
+ ix -= 1
+ while((ix >= 0) && !defaultIndexSet.contains(ix)) ix -= 1
}
theDefaultRows = res
res
}
}
- private def sanity(pos:Position,pvars:Set[Symbol]) {
- if(!pvars.isEmpty) cunit.error(pos, "nonsensical variable binding")
+ private def sanity(pos: Position, pvars: Set[Symbol]) {
+ if (!pvars.isEmpty) cunit.error(pos, "nonsensical variable binding")
}
{
var xs = column
- var i = 0;
- while(xs ne Nil) { // forall
- val (pvars,p) = strip(xs.head)
+ var i = 0
+ while (xs ne Nil) { // forall
+ val (pvars, p) = strip(xs.head)
p match {
case Literal(Constant(c:Int)) => sanity(p.pos, pvars); insertTagIndexPair(c,i)
case Literal(Constant(c:Char)) => sanity(p.pos, pvars); insertTagIndexPair(c.toInt,i)
case p if isDefaultPattern(p) => insertDefault(i,pvars)
}
- i = i + 1
+ i += 1
xs = xs.tail
}
}
@@ -304,18 +306,18 @@ trait ParallelMatching {
*/
class MixUnapply(val scrutinee:Symbol, val column:List[Tree], val rest:Rep) extends RuleApplication {
- def newVarCapture(pos:Position,tpe:Type)(implicit theOwner:Symbol) = {
+ def newVarCapture(pos: Position, tpe: Type)(implicit theOwner: Symbol) = {
val v = newVar(pos,tpe)
- if(scrutinee.hasFlag(symtab.Flags.CAPTURED))
+ if (scrutinee.hasFlag(symtab.Flags.CAPTURED))
v.setFlag(symtab.Flags.CAPTURED) // propagate "unchecked"
v
}
- private def bindToScrutinee(x:Symbol) = typedValDef(x,Ident(scrutinee))
+ private def bindToScrutinee(x: Symbol) = typedValDef(x, Ident(scrutinee))
val unapp = strip2(column.head)
/** returns the (un)apply and two continuations */
- var rootvdefs:List[Tree] = Nil // later, via bindToScrutinee
+ var rootvdefs: List[Tree] = Nil // later, via bindToScrutinee
final def getTransition(implicit theOwner: Symbol): (Tree, List[Tree], Rep, Option[Rep]) = {
unapp match {
@@ -338,8 +340,8 @@ trait ParallelMatching {
case UnApply(Apply(fn1,_),args) if (fn.symbol == fn1.symbol) =>
rootvdefs = (strip1(pat).toList map bindToScrutinee) ::: rootvdefs
Row(EmptyTree::ps, subst, g, b)
- case _ =>
- Row( pat ::ps, subst, g, b)
+ case _ =>
+ Row(pat ::ps, subst, g, b)
}}
(uacall, rootvdefs, Rep(ntemps, nrows), nrepFail)
@@ -348,10 +350,10 @@ trait ParallelMatching {
val vsym = newVarCapture(ua.pos, vtpe)
val ntemps = vsym :: scrutinee :: rest.temp
val nrows = column.zip(rest.row) map { case (pat, Row(ps,subst,g,b)) => strip2(pat) match {
- case UnApply(Apply(fn1,_),args) if (fn.symbol == fn1.symbol) =>
+ case UnApply(Apply(fn1,_), args) if (fn.symbol == fn1.symbol) =>
rootvdefs = (strip1(pat).toList map bindToScrutinee) ::: rootvdefs
Row(args(0) :: EmptyTree :: ps, subst, g, b)
- case _ =>
+ case _ =>
Row(EmptyTree :: pat :: ps, subst, g, b)
}}
(uacall, rootvdefs:::List( typedValDef(vsym, Select(Ident(ures), nme.get))), Rep(ntemps, nrows), nrepFail)
@@ -373,7 +375,7 @@ trait ParallelMatching {
vsyms = vchild :: vsyms
dummies = EmptyTree::dummies
ts = ts.tail
- i = i + 1
+ i += 1
}
val ntemps = vsyms.reverse ::: scrutinee :: rest.temp
dummies = dummies.reverse
@@ -381,7 +383,7 @@ trait ParallelMatching {
case UnApply(Apply(fn1,_),args) if (fn.symbol == fn1.symbol) =>
rootvdefs = (strip1(pat).toList map bindToScrutinee) ::: rootvdefs
Row( args::: EmptyTree ::ps, subst, g, b)
- case _ =>
+ case _ =>
Row(dummies::: pat ::ps, subst, g, b)
}}
(uacall, rootvdefs:::vdefs.reverse, Rep(ntemps, nrows), nrepFail)
@@ -395,7 +397,7 @@ trait ParallelMatching {
class MixTypes(val scrutinee:Symbol, val column:List[Tree], val rest:Rep) extends RuleApplication {
var casted: Symbol = null
- var moreSpecific: List[Tree] = Nil
+ var moreSpecific: List[Tree] = Nil
var subsumed: List[(Int,List[Tree])] = Nil // row index and subpatterns
var remaining: List[(Int,Tree)] = Nil // row index and pattern
@@ -405,7 +407,7 @@ trait ParallelMatching {
scrutinee.tpe.typeSymbol.children.forall { sym => tpes.contains(sym) }
}
- private val patternType = column.head match {
+ private val patternType = column.head match {
case p @ (_:Ident | _:Select) =>
singleType(p.symbol.tpe.prefix, p.symbol) //ConstantType(p.tpe.singleton)
//case p@Apply(_,_) if !p.tpe.typeSymbol.hasFlag(symtab.Flags.CASE) => ConstantType(new NamedConstant(p))
@@ -417,18 +419,18 @@ trait ParallelMatching {
//Console.println("isCaseHead = "+isCaseHead)
//Console.println("dummies = "+dummies)
- private def subpatterns(pat:Tree): List[Tree] = {
+ private def subpatterns(pat: Tree): List[Tree] = {
//Console.print("subpatterns("+pat+")=")
//val x =
pat match {
- case Bind(_,p) =>
+ case Bind(_, p) =>
subpatterns(p)
case app @ Apply(fn, pats) if app.tpe.typeSymbol.hasFlag(symtab.Flags.CASE) && (fn.symbol eq null)=>
pats
case Apply(fn,xs) => assert((xs.isEmpty) && (fn.symbol ne null)); dummies // named constant
- case _: UnApply =>
+ case _: UnApply =>
dummies
- case pat =>
+ case pat =>
dummies
}
//Console.println(x)
@@ -436,7 +438,7 @@ trait ParallelMatching {
}
/** returns true if pattern tests an object */
- final def objectPattern(pat:Tree): Boolean = try {
+ final def objectPattern(pat: Tree): Boolean = try {
(pat.symbol ne null) &&
(pat.symbol != NoSymbol) &&
pat.symbol.tpe.prefix.isStable &&
@@ -444,7 +446,7 @@ trait ParallelMatching {
} catch {
case e =>
Console.println("object pattern test throws "+e.getMessage())
- if(settings_debug)
+ if (settings_debug)
System.exit(-1);
throw e
}
@@ -493,7 +495,7 @@ trait ParallelMatching {
//Console.println("current pattern tests something else")
(ms,ss,(j,pat)::rs)
}
- j = j + 1
+ j += 1
pats = pats.tail
}
this.moreSpecific = sr._1.reverse
@@ -542,7 +544,7 @@ trait ParallelMatching {
}
ntemps = ntemps ::: rest.temp
val ntriples = subtests map {
- case (j,pats) =>
+ case (j, pats) =>
val (vs,thePat) = strip(column(j))
val Row(opats,osubst,og,ob) = rest.row(j)
val subst1 = //if(!moreSpecificIndices.isEmpty && moreSpecificIndices.contains(j)) Nil /*morespecific?*/ else
@@ -559,7 +561,7 @@ trait ParallelMatching {
// BTW duplicating body/guard, gets you "defined twice" error cause hashing breaks
}
- if(settings_debug) {
+ if (settings_debug) {
Console.println("ntemps = "+ntemps.mkString("[["," , ","]]"))
Console.println("ntriples = "+ntriples.mkString("[["," , ","]]"))
}
@@ -576,7 +578,7 @@ trait ParallelMatching {
//Console.println("nmatrixfail triples:"+ntriples)
if(ntriples.isEmpty) None else Some(Rep(ntemps, ntriples) /*setParent this*/)
}
- if(!nmatrixFail.isEmpty) {
+ if (!nmatrixFail.isEmpty) {
//DEBUG("nmatrix for failing type test "+patternType)
//DEBUG(nmatrixFail.get.toString)
} else {
@@ -588,7 +590,7 @@ trait ParallelMatching {
final def genBody(subst: List[Pair[Symbol,Symbol]], b:Tree)(implicit theOwner: Symbol, bodies: collection.mutable.Map[Tree,(Tree, Tree, Symbol)]): Tree = {
- if(b.isInstanceOf[Literal]) { // small trees
+ if (b.isInstanceOf[Literal]) { // small trees
bodies(b) = null // placeholder, for unreachable-code-detection
return typed{ b.duplicate }
} else if (b.isInstanceOf[Throw]) {
@@ -635,7 +637,7 @@ trait ParallelMatching {
}
/** converts given rep to a tree - performs recursive call to translation in the process to get sub reps
*/
- final def repToTree(rep:Rep, handleOuter: Tree => Tree)(implicit theOwner: Symbol, failTree: Tree, bodies: collection.mutable.Map[Tree,(Tree, Tree, Symbol)]): Tree = {
+ final def repToTree(rep: Rep, handleOuter: Tree => Tree)(implicit theOwner: Symbol, failTree: Tree, bodies: collection.mutable.Map[Tree,(Tree, Tree, Symbol)]): Tree = {
rep.applyRule match {
case VariableRule(subst, EmptyTree, b) =>
genBody(subst,b)
@@ -654,7 +656,7 @@ trait ParallelMatching {
Console.println("]]")
}
- var ndefault = if(default.isEmpty) failTree else repToTree(default.get, handleOuter)
+ var ndefault = if (default.isEmpty) failTree else repToTree(default.get, handleOuter)
var cases = branches map {
case (tag, rep) =>
@@ -694,7 +696,7 @@ trait ParallelMatching {
case ml: MixLiterals =>
val (branches, defaultV, defaultRepOpt) = ml.getTransition // tag body pairs
- if(settings_debug) {
+ if (settings_debug) {
Console.println("[[mix literal transition: branches \n"+(branches.mkString("","\n","")))
Console.println("defaults:"+defaultV)
Console.println(defaultRepOpt)
@@ -724,7 +726,7 @@ trait ParallelMatching {
val condUntyped = condition(casted.tpe, mm.scrutinee)
//Console.println("condUntyped:" + condUntyped)
var cond = handleOuter(typed { condUntyped }) // this thing throws exceptions in some obscure situations
- if(needsOuterTest(casted.tpe, mm.scrutinee.tpe)) // @todo merrge into def condition
+ if (needsOuterTest(casted.tpe, mm.scrutinee.tpe)) // @todo merrge into def condition
cond = addOuterCondition(cond, casted.tpe, typed{Ident(mm.scrutinee)}, handleOuter)
val succ = repToTree(srep, handleOuter)
@@ -871,8 +873,8 @@ object Rep {
}
abstract class Rep {
- val temp:List[Symbol]
- val row:List[Row] // (List[Tree], List[(Symbol,Symbol)], Tree, Tree)
+ val temp: List[Symbol]
+ val row: List[Row] // (List[Tree], List[(Symbol,Symbol)], Tree, Tree)
var sealedCols = List[Int]()
var sealedComb = List[Set[Symbol]]()
@@ -880,7 +882,7 @@ object Rep {
final def init: this.type = {
temp.zipWithIndex.foreach {
- case (sym,i) =>
+ case (sym, i) =>
//Console.println("sym! "+sym+" mutable? "+sym.hasFlag(symtab.Flags.MUTABLE)+" captured? "+sym.hasFlag(symtab.Flags.CAPTURED))
if (sym.hasFlag(symtab.Flags.MUTABLE) && // indicates that have not yet checked exhaustivity
!sym.hasFlag(symtab.Flags.CAPTURED) && // indicates @unchecked
@@ -907,7 +909,7 @@ object Rep {
case (i,syms)::cs => for (s <- syms.toList; rest <- combine(cs)) yield (i,s) :: rest
}
- if(!sealedCols.isEmpty) {
+ if (!sealedCols.isEmpty) {
//Console.println("cols"+sealedCols)
//DEBUG("comb")
//for (com <- sealedComb) //DEBUG(com.toString)
@@ -920,25 +922,25 @@ object Rep {
*/
def covers(pats: List[Tree], comb:List[(Int,Symbol)]) =
comb forall {
- case (i,sym) =>
+ case (i, sym) =>
val p = strip2(pats(i));
- val res =
- isDefaultPattern(p) || {
- val symtpe = if(sym.hasFlag(symtab.Flags.MODULE)) {
- singleType(sym.tpe.prefix, sym.linkedModuleOfClass) // e.g. None, Nil
- } else sym.tpe
- //Console.print("covers: sym="+sym+" symtpe="+symtpe+" p="+p+", p.tpe="+p.tpe+" ?")
- (p.tpe.typeSymbol == sym) || (symtpe <:< p.tpe) ||
- /* outer, see scala.util.parsing.combinator.lexical.Scanner */
- (p.tpe.prefix.memberType(sym) <:< p.tpe)
- }
- //Console.println(res)
- res
+ val res =
+ isDefaultPattern(p) || {
+ val symtpe = if (sym.hasFlag(symtab.Flags.MODULE)) {
+ singleType(sym.tpe.prefix, sym.linkedModuleOfClass) // e.g. None, Nil
+ } else sym.tpe
+ //Console.print("covers: sym="+sym+" symtpe="+symtpe+" p="+p+", p.tpe="+p.tpe+" ?")
+ (p.tpe.typeSymbol == sym) || (symtpe <:< p.tpe) ||
+ /* outer, see scala.util.parsing.combinator.lexical.Scanner */
+ (p.tpe.prefix.memberType(sym) <:< p.tpe)
+ }
+ //Console.println(res)
+ res
}
val coversAll = allcomb forall { combination => row exists { r => covers(r.pat, combination)}}
//Console.println("all combinations covered? "+coversAll)
- if(!coversAll) {
+ if (!coversAll) {
val sb = new StringBuilder()
sb.append("match is not exhaustive!\n")
for (open <- allcomb if !(row exists { r => covers(r.pat, open)})) {
@@ -1036,14 +1038,14 @@ object Rep {
*/
final def strip(x: Tree): (Set[Symbol], Tree) = x match {
case b @ Bind(_,pat) => val (vs, p) = strip(pat); (vs + b.symbol, p)
- case z => (emptySymbolSet, z)
+ case z => (emptySymbolSet,z)
}
- final def strip1(x:Tree): Set[Symbol] = x match { // same as strip(x)._1
+ final def strip1(x: Tree): Set[Symbol] = x match { // same as strip(x)._1
case b @ Bind(_,pat) => strip1(pat) + b.symbol
case z => emptySymbolSet
}
- final def strip2(x:Tree): Tree = x match { // same as strip(x)._2
+ final def strip2(x: Tree): Tree = x match { // same as strip(x)._2
case Bind(_,pat) => strip2(pat)
case z => z
}
@@ -1075,7 +1077,7 @@ object Rep {
}
final def condition1(tpe: Type, scrut: Symbol): Tree = {
assert(scrut ne NoSymbol)
- condition(tpe, Ident(scrut) setType scrut.tpe setSymbol scrut)
+ condition(tpe, Ident(scrut) setType(scrut.tpe) setSymbol(scrut))
}
final def condition(tpe: Type, scrutineeTree: Tree): Tree = {
@@ -1099,7 +1101,7 @@ object Rep {
//Console.println("tpe prefix stable "+tpe.prefix.isStable)
//val x = Equals(Apply(gen.mkAttributedRef(tpe.typeSymbol), List()), scrutineeTree)
val x =
- if(tpe.prefix ne NoPrefix) gen.mkIsInstanceOf(scrutineeTree, tpe)
+ if (tpe.prefix ne NoPrefix) gen.mkIsInstanceOf(scrutineeTree, tpe)
else Equals(gen.mkAttributedRef(tpe.typeSymbol), scrutineeTree)
//Console.println(" = "+x)
typed { x }
@@ -1117,24 +1119,24 @@ object Rep {
} else if (scrutineeTree.tpe <:< tpe && tpe <:< definitions.AnyRefClass.tpe) {
//if(scrutineeTree.symbol.hasFlag(symtab.Flags.SYNTHETIC)) Literal(Constant(true)) else
NotNull(scrutineeTree)
- } else if(tpe.prefix.typeSymbol.isTerm && tpe.typeSymbol.linkedModuleOfClass != NoSymbol) { // object
+ } else if (tpe.prefix.typeSymbol.isTerm && tpe.typeSymbol.linkedModuleOfClass != NoSymbol) { // object
//Console.println("iT"+tpe.prefix.symbol.isTerm)
- //Console.println("lmoc"+tpe.typeSymbol.linkedModuleOfClass)
+ //Console.println("lmoc"+tpe.symbol.linkedModuleOfClass)
Eq(gen.mkAttributedRef(tpe.prefix, tpe.typeSymbol.linkedModuleOfClass), scrutineeTree)
} else
//Console.println(tpe.prefix.symbol.isTerm)
- //Console.println(tpe.typeSymbol)
- //Console.println(tpe.typeSymbol.linkedModuleOfClass)
+ //Console.println(tpe.symbol)
+ //Console.println(tpe.symbol.linkedModuleOfClass)
gen.mkIsInstanceOf(scrutineeTree, tpe)
}
final def needsOuterTest(tpe2test: Type, scrutinee: Type) = tpe2test.normalize match {
case TypeRef(prefix,_,_) =>
- prefix.typeSymbol.isTerm &&
- !prefix.typeSymbol.isPackage &&
+ prefix.symbol.isTerm &&
+ !prefix.symbol.isPackage &&
outerAlwaysEqual(tpe2test, scrutinee) == Some(false)
case _ =>
- false
+ false
}
/** returns a result if both are TypeRefs, returns Some(true) if left and right are statically known to have
@@ -1152,9 +1154,9 @@ object Rep {
}
/** adds a test comparing the dynamic outer to the static outer */
- final def addOuterCondition(cond:Tree, tpe2test: Type, scrutinee: Tree, handleOuter: Tree=>Tree) = {
+ final def addOuterCondition(cond: Tree, tpe2test: Type, scrutinee: Tree, handleOuter: Tree=>Tree) = {
val TypeRef(prefix,_,_) = tpe2test
- var theRef = gen.mkAttributedRef(prefix.prefix, prefix.typeSymbol)
+ var theRef = gen.mkAttributedRef(prefix.prefix, prefix.symbol)
// needs explicitouter treatment
theRef = handleOuter(theRef)
@@ -1166,7 +1168,7 @@ object Rep {
} else
And(cond,
Eq(Apply(Select(
- gen.mkAsInstanceOf(scrutinee, tpe2test, true), outerAcc),List()), theRef))
+ gen.mkAsInstanceOf(scrutinee, tpe2test, true), outerAcc), List()), theRef))
}
diff --git a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
index b6b483ae5f..aab9ad480f 100644
--- a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
+++ b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
@@ -1089,7 +1089,7 @@ print()
var nCases: List[CaseDef] = Nil
while (cases ne null) {
- if(inheritsFromSealed(cases.node.tpe)) {
+ if (inheritsFromSealed(cases.node.tpe)) {
val t = toTree_refined(cases.node, selector, true)
//Console.println("optimize this"+t+" from this "+cases.node)
nCases = CaseDef(Literal(Constant(cases.tag)),
@@ -1122,7 +1122,7 @@ print()
def myIf(cond: Tree, thenp: Tree, elsep: Tree) =
Or(And(cond, thenp), elsep)
- protected def toTree(node: PatternNode, selector:Tree): Tree = {
+ protected def toTree(node: PatternNode, selector: Tree): Tree = {
val t = toTree_refined(node, selector, false)
try {
//Console.println("type-checking "+t)
@@ -1137,16 +1137,16 @@ print()
}
}
- protected def toTree_refined(node: PatternNode, selector:Tree, ignoreSelectorType: Boolean): Tree = {
+ protected def toTree_refined(node: PatternNode, selector: Tree, ignoreSelectorType: Boolean): Tree = {
//Console.println("pm.toTree("+node+","+selector+") selector.tpe = "+selector.tpe+")")
if (selector.tpe eq null)
scala.Predef.error("cannot go on due to internal error (type attribute set to null)")
if (node eq null)
- return Literal(Constant(false));
+ return Literal(Constant(false))
else
node match {
case DefaultPat() =>
- return toTree(node.and);
+ return toTree(node.and)
case UnapplyPat(casted, Apply(fn1, appargs)) if casted.tpe.typeSymbol == defs.BooleanClass => // special case
var useSelector = selector
@@ -1234,7 +1234,7 @@ print()
val cast_untyped = gen.mkAsInstanceOf(selector.duplicate, ntpe, true)
val vdef_untyped = typedValDef(casted,
- if(isSubType(selector.tpe,ntpe))
+ if (isSubType(selector.tpe,ntpe))
selector.duplicate
else
cast_untyped)
@@ -1284,7 +1284,7 @@ print()
val ntpe = node.tpe
val tpetest =
- if(!isSubType(selector.tpe,ntpe))
+ if (!isSubType(selector.tpe,ntpe))
gen.mkIsInstanceOf(selector.duplicate, ntpe);
else
Literal(Constant(true))
@@ -1300,7 +1300,7 @@ print()
else And(tpetest, seqLongerThan(treeAsSeq, ntpe, minlen))
var bindings =
- if(castedRest ne null)
+ if (castedRest ne null)
List(typedValDef(castedRest, seqDrop(treeAsSeq.duplicate, minlen)))
else
List()