From 98abb80c3cd862d81fe41ea299b96f44f5de91d3 Mon Sep 17 00:00:00 2001 From: David MacIver Date: Sat, 25 Oct 2008 12:16:03 +0000 Subject: Fixed 1424. --- .../scala/tools/nsc/matching/ParallelMatching.scala | 19 ++++++++++++++----- test/files/run/t1424.check | 1 + test/files/run/t1424.scala | 8 ++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 test/files/run/t1424.check create mode 100644 test/files/run/t1424.scala diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala index 6a02957e3e..02495dd61a 100644 --- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala +++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala @@ -43,11 +43,20 @@ trait ParallelMatching { def MixtureRule(scrutinee: Symbol, column: List[Tree], rest: Rep)(implicit rep: RepFactory): RuleApplication = { def isSimpleSwitch: Boolean = { + val simpleSwitchCandidate = (tree : Tree) => strip2(tree) match { + case Literal(const : Constant) if isNumeric(const.tag) => + const.tag match { + case FloatTag | DoubleTag | LongTag => false; + case _ => true; + } + case _ => false; + } + (isSameType(scrutinee.tpe.widen, definitions.IntClass.tpe) || isSameType(scrutinee.tpe.widen, definitions.CharClass.tpe)) && - column.init.forall(h => strip2(h).isInstanceOf[Literal]) && { + column.init.forall(simpleSwitchCandidate) && { val last = column.last; - last.isInstanceOf[Literal] || isDefaultPattern(last); + simpleSwitchCandidate(last) || isDefaultPattern(last); }} // an unapply for which we don't need a type test @@ -327,11 +336,11 @@ trait ParallelMatching { myBindVars(varMap, orig) } - /*block*/{ + { var xs = column var i = 0; var last = -1; - while(xs ne Nil) { // forall + while(xs ne Nil) { if (last != -1) { cunit.error(xs.head.pos, "unreachable code") } @@ -348,7 +357,7 @@ trait ParallelMatching { i += 1 xs = xs.tail } - }/*end block*/ + } final def tree(implicit theOwner: Symbol, failTree: Tree): Tree = { val (branches, defaultV, defaultRepOpt) = this.getTransition // tag body pairs diff --git a/test/files/run/t1424.check b/test/files/run/t1424.check new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/test/files/run/t1424.check @@ -0,0 +1 @@ +1 diff --git a/test/files/run/t1424.scala b/test/files/run/t1424.scala new file mode 100644 index 0000000000..83c35a46bd --- /dev/null +++ b/test/files/run/t1424.scala @@ -0,0 +1,8 @@ +object Test extends Application{ + val x = 1 match { + case 0xFFFFFFFF00000001L => println("Oops, overflow!"); + case 2L => println(2); + case 1L => println(1); + case _ => println("????"); + } +} -- cgit v1.2.3