Skip to content

Commit ebb01e0

Browse files
committed
SI-7020 Determinism for pattern matcher warnings
Use LinkedHashSet for the DPLL algorithm for determistic counter example generation. Before, the test compiled with: [info] v2.10.2 => /Users/jason/usr/scala-v2.10.2-0-g60d462e test/files/neg/t7020.scala:3: warning: match may not be exhaustive. It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List(_, _) List(5) match { ^ test/files/neg/t7020.scala:10: warning: match may not be exhaustive. It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List(_, _) List(5) match { ^ test/files/neg/t7020.scala:17: warning: match may not be exhaustive. It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 6, 7)), _), List(1, _), List(2, _), List(4, _), List(5, _), List(6, _), List(7, _), List(??, _) List(5) match { ^ test/files/neg/t7020.scala:24: warning: match may not be exhaustive. It would fail on the following input: List(_, _) List(5) match { ^
1 parent 1a03184 commit ebb01e0

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

src/compiler/scala/tools/nsc/transform/patmat/Solving.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,16 @@ trait Solving extends Logic {
208208
withLit(findModelFor(dropUnit(f, unitLit)), unitLit)
209209
case _ =>
210210
// partition symbols according to whether they appear in positive and/or negative literals
211-
val pos = new mutable.HashSet[Sym]()
212-
val neg = new mutable.HashSet[Sym]()
211+
// SI-7020 Linked- for deterministic counter examples.
212+
val pos = new mutable.LinkedHashSet[Sym]()
213+
val neg = new mutable.LinkedHashSet[Sym]()
213214
f.foreach{_.foreach{ lit =>
214215
if (lit.pos) pos += lit.sym else neg += lit.sym
215216
}}
216217
// appearing in both positive and negative
217-
val impures = pos intersect neg
218+
val impures: mutable.LinkedHashSet[Sym] = pos intersect neg
218219
// appearing only in either positive/negative positions
219-
val pures = (pos ++ neg) -- impures
220+
val pures: mutable.LinkedHashSet[Sym] = (pos ++ neg) -- impures
220221

221222
if (pures nonEmpty) {
222223
val pureSym = pures.head

test/files/neg/t7020.check

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
t7020.scala:3: error: match may not be exhaustive.
2+
It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List(_, _)
3+
List(5) match {
4+
^
5+
t7020.scala:10: error: match may not be exhaustive.
6+
It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List(_, _)
7+
List(5) match {
8+
^
9+
t7020.scala:17: error: match may not be exhaustive.
10+
It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List(_, _)
11+
List(5) match {
12+
^
13+
t7020.scala:24: error: match may not be exhaustive.
14+
It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List(_, _)
15+
List(5) match {
16+
^
17+
four errors found

test/files/neg/t7020.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Xfatal-warnings

test/files/neg/t7020.scala

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
object Test {
2+
// warning was non-deterministic
3+
List(5) match {
4+
case 1 :: Nil | 2 :: Nil =>
5+
case (x@(4 | 5 | 6)) :: Nil =>
6+
case 7 :: Nil =>
7+
case Nil =>
8+
}
9+
10+
List(5) match {
11+
case 1 :: Nil | 2 :: Nil =>
12+
case (x@(4 | 5 | 6)) :: Nil =>
13+
case 7 :: Nil =>
14+
case Nil =>
15+
}
16+
17+
List(5) match {
18+
case 1 :: Nil | 2 :: Nil =>
19+
case (x@(4 | 5 | 6)) :: Nil =>
20+
case 7 :: Nil =>
21+
case Nil =>
22+
}
23+
24+
List(5) match {
25+
case 1 :: Nil | 2 :: Nil =>
26+
case (x@(4 | 5 | 6)) :: Nil =>
27+
case 7 :: Nil =>
28+
case Nil =>
29+
}
30+
}

0 commit comments

Comments
 (0)