summaryrefslogtreecommitdiff
path: root/src/ast_util.mli
diff options
context:
space:
mode:
authorAlasdair Armstrong2018-01-25 19:05:39 +0000
committerAlasdair Armstrong2018-01-25 19:08:27 +0000
commitb7e388f0193a89608687760f50e476c059f0f49c (patch)
tree8de862216287fd9b5b7a2cd9256b11fd3688bee4 /src/ast_util.mli
parent2ee59d0eee7508ebe4e84b4cf2468d8631b2c418 (diff)
Add pattern completness check for match statements
Gives warnings when pattern matches are incomplete, when matches are redundant (in certain cases), or when no unguarded patterns exist. For example the following file: enum Test = {A, C, D} val test1 : Test -> string function test1 x = match x { A => "match A", B => "this will match anything, because B is unbound!", C => "match C", D => "match D" } val test2 : Test -> string function test2 x = match x { A => "match A", C => "match C" /* No match for D */ } val test3 : Test -> string function test3 x = match x { A if false => "never match A", C => "match C", D => "match D" } val test4 : Test -> string function test4 x = match x { A if true => "match A", C if true => "match C", D if true => "match D" } will produce the following warnings Warning: Possible redundant pattern match at file "test.sail", line 10, character 5 to line 10, character 5 C => "match C", Warning: Possible redundant pattern match at file "test.sail", line 11, character 5 to line 11, character 5 D => "match D" Warning: Possible incomplete pattern match at file "test.sail", line 17, character 3 to line 17, character 7 match x { Most general matched pattern is A_|C_ Warning: Possible incomplete pattern match at file "test.sail", line 26, character 3 to line 26, character 7 match x { Most general matched pattern is C_|D_ Warning: No non-guarded patterns at file "test.sail", line 35, character 3 to line 35, character 7 match x { warnings can be turned of with the -no_warn flag.
Diffstat (limited to 'src/ast_util.mli')
-rw-r--r--src/ast_util.mli9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/ast_util.mli b/src/ast_util.mli
index c9869cce..4452ee3f 100644
--- a/src/ast_util.mli
+++ b/src/ast_util.mli
@@ -53,6 +53,13 @@
open Ast
module Big_int = Nat_big_num
+type mut = Immutable | Mutable
+
+(** [lvar] is the type of variables - they can either be registers,
+ local mutable or immutable variables, nullary union constructors
+ (i.e. None in option), or unbound identifiers *)
+type lvar = Register of typ | Enum of typ | Local of mut * typ | Union of typquant * typ | Unbound
+
val no_annot : unit annot
val gen_loc : Parse_ast.l -> Parse_ast.l
@@ -293,3 +300,5 @@ val rename_fundef : id -> 'a fundef -> 'a fundef
val split_defs : ('a def -> bool) -> 'a defs -> ('a defs * 'a def * 'a defs) option
val append_ast : 'a defs -> 'a defs -> 'a defs
+
+val type_union_id : type_union -> id