-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: add several regression tests for pattern matching
For issues #829, #1121, #1228, #1903 and #1954. The PatternMatch.fst file also constains some various examples. While at it, also add a check for #1956 (even if it never manifested).
- Loading branch information
Showing
9 changed files
with
201 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Bug1121 | ||
|
||
[@(expect_failure [138])] | ||
let foo () : Tot int = | ||
match (1,2) with | ||
| (x,x) -> x | ||
|
||
[@(expect_failure [138])] | ||
let foo2 x = match x with (x,x) -> 1 | ||
|
||
[@(expect_failure [138])] | ||
let foo3 x x = 42 | ||
|
||
[@(expect_failure [138])] | ||
let foo4 (x:int) = | ||
let inner_foo x x = x + x in | ||
inner_foo x x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Bug1228 | ||
|
||
[@(expect_failure [19])] | ||
let 2 = 4 // Incomplete pattern (ok in OCaml) | ||
|
||
[@(expect_failure [19])] | ||
let [] = [1] // idem | ||
|
||
[@(expect_failure [178])] | ||
let 2: int = 4 // Incomplete pattern (ok in OCaml) | ||
|
||
[@(expect_failure [178])] | ||
let []: list int = [1] // idem | ||
|
||
[@(expect_failure [178])] | ||
let (): int = 4 // int to unit? | ||
|
||
let foo (x: int): int = x | ||
|
||
[@(expect_failure [114])] | ||
let () = foo // function to unit? | ||
|
||
[@(expect_failure [114])] | ||
let 3 = foo // function to int? | ||
|
||
[@(expect_failure [114])] | ||
let 4 = [1; 2; 3] // list int to int? | ||
|
||
[@(expect_failure [178])] | ||
let (): int -> int = foo // function to unit? | ||
|
||
[@(expect_failure [178])] | ||
let 3: int -> int = foo // function to int? | ||
|
||
[@(expect_failure [178])] | ||
let 4: list int = [1; 2; 3] // list int to int? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Bug1903 | ||
|
||
[@(expect_failure [178])] (* bad ascription *) | ||
let None : option unit = Some () | ||
|
||
[@(expect_failure [19])] (* incomplete match *) | ||
let None = Some () | ||
|
||
[@(expect_failure [72])] (* X unbound *) | ||
let X = 42 | ||
|
||
[@(expect_failure [114])] (* type doesn't match *) | ||
let None = 42 | ||
|
||
[@(expect_failure [19])] (* incomplete match *) | ||
let 0 = 1 | ||
|
||
let 0 = 0 (* OK *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Bug1954 | ||
|
||
(* disable warning about needless let rec *) | ||
#set-options "--warn_error -328" | ||
|
||
[@(expect_failure [178])] | ||
let blah = match None with | (None : option int) -> () | ||
|
||
let addp ((x, y) : int & int) : int = x + y | ||
let rec rec_addp ((x, y) : int & int) : int = x + y | ||
|
||
let addp' = fun ((x,y) : int & int) -> x + y <: int | ||
let rec rec_addp' = fun ((x,y) : int & int) -> x + y <: int | ||
|
||
type box a = | Box of a | ||
|
||
let unbox (Box x) : int = x | ||
|
||
let unbox' (Box x : box int) : int = x | ||
|
||
let unbox'' (Box (x : int) : box int) : int = x | ||
|
||
[@(expect_failure [178])] | ||
let g b = | ||
match b with | ||
| (Box x : box int) -> x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Bug1956 | ||
|
||
[@expect_failure] | ||
let xx : squash False = () | ||
|
||
// This can succeed if `xx` leaks into the SMT context for this query | ||
[@expect_failure] | ||
let _ = assert False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Bug829 | ||
|
||
type r = { x : int } | ||
|
||
[@(expect_failure [114])] | ||
let true = 2 | ||
|
||
[@(expect_failure [114])] | ||
let { x = true } = { x = 2 } | ||
|
||
[@(expect_failure [19])] | ||
let (x, true) = (2, false) | ||
|
||
let (x, true) = (2, true) | ||
|
||
[@(expect_failure [19])] | ||
let (false, false, xx) = (true, true, 9) | ||
|
||
[@(expect_failure [114])] | ||
let (true, true) = (2, false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module PatternMatch | ||
|
||
(* Error 19: assertion failed (from incomplete pattern matching in this case | ||
* Error 114: Type of pattern __ does not match type of scrutinee __ | ||
* Error 178: Type ascriptions within patterns are only allowed on variables [2 times] | ||
*) | ||
|
||
let _ = (=) | ||
|
||
let pair_on_arg ((x,y) : int & int) : int = x + y | ||
|
||
type ab = | A | B | ||
|
||
[@(expect_failure [178])] | ||
let oops2 = match A with | (A : _) -> () | ||
|
||
[@(expect_failure [178])] | ||
let blah = match None with | (None : option int) -> () | ||
|
||
[@(expect_failure [19])] | ||
let None = Some 42 | ||
|
||
[@(expect_failure [19])] | ||
let Some () = None | ||
|
||
let true = true | ||
|
||
[@(expect_failure [19])] | ||
let true = false | ||
|
||
[@(expect_failure [114])] | ||
let false = 1 | ||
|
||
[@(expect_failure [114])] | ||
let A = 2 | ||
|
||
[@(expect_failure [19])] | ||
let A = B | ||
|
||
[@(expect_failure [178])] | ||
let None : option unit = Some 42 | ||
|
||
let x1, y1 = 42, true | ||
let ((x2 : int), (y2 : bool)) = (42, true) | ||
|
||
let _ = assert (x1 == 42) | ||
let _ = assert (y1 == true) | ||
let _ = assert (x2 == 42) | ||
let _ = assert (y2 == true) | ||
|
||
|
||
type r = { x : int } | ||
|
||
[@(expect_failure [114])] | ||
let true = 2 | ||
|
||
[@(expect_failure [114])] | ||
let { x = true } = { x = 2 } | ||
|
||
[@(expect_failure [19])] | ||
let (x, true) = (2, false) | ||
|
||
[@(expect_failure [19])] | ||
let (false, false, x) = (true, true, 9) | ||
|
||
let (x, true) = (2, true) | ||
|
||
[@(expect_failure [114])] | ||
let (true, true) = (2, false) | ||
|
||
let (z, 0) = (42, 0) | ||
|
||
let () = () |