summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/matching/PatternMatchers.scala22
-rw-r--r--src/compiler/scala/tools/nsc/matching/PatternNodes.scala9
2 files changed, 14 insertions, 17 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
index 0cc4145d0a..3b4a88e63c 100644
--- a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
+++ b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
@@ -435,6 +435,7 @@ trait PatternMatchers requires (transform.ExplicitOuter with PatternNodes) {
node
case t @ UnApply(fn, args) =>
+ doCheckExhaustive = false // just seeing unapply pattern disables exhaustiveness check for whole match
pUnapplyPat(tree.pos, fn)
case t @ Apply(fn, args) => // pattern with args
@@ -692,8 +693,7 @@ print()
} else {
//Console.println(" enter: using old header for casted = "+casted) // DBG
// find most recent header
- while (curHeader.next ne null)
- curHeader = curHeader.next
+ curHeader = curHeader.findLastSection
// create node
var patNode = patternNode(pat, curHeader, env)
var next: PatternNode = curHeader
@@ -886,17 +886,6 @@ print()
if (null == next) 1 else (next.length() + 1)
}
- protected def numCases(patNode1: PatternNode): Int = {
- var patNode = patNode1
- var n = 0
- while (({patNode = patNode.or; patNode}) ne null)
- patNode match {
- case DefaultPat() => ;
- case _ => n = n + 1
- }
- n
- }
-
protected def defaultBody(patNode1: PatternNode, otherwise: Tree ): Tree = {
patNode1.asInstanceOf[Header].forEachSection {
case h:Header => h.forEachBranch {
@@ -921,7 +910,12 @@ print()
}
//print();
- val ncases = numCases(root.and)
+ var ncases = 0
+ root.and.asInstanceOf[Header].forEachBranch {
+ case DefaultPat() => ;
+ case _ => ncases = ncases + 1
+ }
+
val matchError = ThrowMatchError(selector.pos, Ident(root.symbol))
// without a case, we return a match error if there is no default case
if (ncases == 0)
diff --git a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
index 74698ac05b..cd0d5da3d8 100644
--- a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
+++ b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
@@ -298,13 +298,16 @@ trait PatternNodes requires transform.ExplicitOuter {
var next: Header = next1
def findLast: PatternNode = {
- var h: Header = this;
- while(h.next != null) { h = h.next }
- var g: PatternNode = h
+ var g: PatternNode = findLastSection
while(g.or != null) { g = g.or }
g
}
+ def findLastSection: Header = {
+ var h: Header = this;
+ while(h.next != null) { h = h.next }
+ h
+ }
var isSubHeader = false;
// returns true if this header node has a catch all case