summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlain Frisch <alain@frisch.fr>2006-09-09 21:16:57 +0000
committerAlain Frisch <alain@frisch.fr>2006-09-09 21:16:57 +0000
commitbe636db45ba73aeed0ba25bdffe8812bb51f3d03 (patch)
tree1ee348e3bc812e56385f52172bdeee567f15e7fd
parent7b782c9b15a58e88d587b8c008cd00c655dc734d (diff)
downloadocaml-be636db45ba73aeed0ba25bdffe8812bb51f3d03.tar.gz
warning for variables that can only match the empty sequence
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/cducetrunk@7588 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--README.cduce2
-rw-r--r--typing/typeext.ml14
-rw-r--r--utils/warnings.ml3
-rw-r--r--utils/warnings.mli1
4 files changed, 18 insertions, 2 deletions
diff --git a/README.cduce b/README.cduce
index bd7114c43c..0c25557622 100644
--- a/README.cduce
+++ b/README.cduce
@@ -108,3 +108,5 @@ CHANGE LOG:
Since then
- support line number directives within {{ ... }}
+- support non-ascii X-capture variable names
+- warning for variables that always bind to {{ [] }} \ No newline at end of file
diff --git a/typing/typeext.ml b/typing/typeext.ml
index 22f6402009..fea131ac4a 100644
--- a/typing/typeext.ml
+++ b/typing/typeext.ml
@@ -755,8 +755,9 @@ let add_values =
let ext_branch env loc t p a =
let module P = Cduce_types.Patterns in
let fv = P.fv p in
+ let id x = U.to_string (snd x) in
let ids =
- List.map (fun x -> x, Ident.create (Cduce_types.Ident.to_string x)) fv in
+ List.map (fun x -> x, Ident.create (id x)) fv in
let vars =
if !extmode then List.map (fun (_,x) -> x, anyext_var) ids
else
@@ -765,7 +766,16 @@ let ext_branch env loc t p a =
let ta = CT.cap t ta in
if (CT.is_empty ta) && (loc != Location.none) then
Location.prerr_warning loc Warnings.Unused_match;
- P.filter ta p
+ let res = P.filter ta p in
+
+ Cduce_types.Ident.IdMap.iteri
+ (fun x t ->
+ if (CT.subtype (CT.descr t) SEQ.nil_type) then
+ Location.prerr_warning loc (Warnings.Match_epsilon (id x)))
+ res;
+
+ res
+
) in
to_eval := (fun () -> ignore (lazy_force loc z)) :: !to_eval;
(* to get a warning for unused
diff --git a/utils/warnings.ml b/utils/warnings.ml
index 850dd80b85..abcae9b49f 100644
--- a/utils/warnings.ml
+++ b/utils/warnings.ml
@@ -26,6 +26,7 @@ type t = (* A is all *)
| Statement_type (* S *)
| Unused_match (* U *)
| Unused_pat
+ | Match_epsilon of string
| Hide_instance_variable of string (* V *)
| Illegal_backslash (* X *)
| Implicit_public_methods of string list
@@ -53,6 +54,7 @@ let letter = function (* 'a' is all *)
| Partial_match _ -> 'p'
| Statement_type -> 's'
| Unused_match
+ | Match_epsilon _
| Unused_pat -> 'u'
| Hide_instance_variable _ -> 'v'
| Illegal_backslash
@@ -113,6 +115,7 @@ let message = function
Here is an example of a value that is not matched:\n" ^ s
| Unused_match -> "this match case is unused."
| Unused_pat -> "this pattern is unused."
+ | Match_epsilon s -> "the variable " ^ s ^ " can only match the empty sequence."
| Fragile_pat "" ->
"this pattern is fragile. It would hide\n\
the addition of new constructors to the data types it matches."
diff --git a/utils/warnings.mli b/utils/warnings.mli
index 5f22c91bea..0e467a340d 100644
--- a/utils/warnings.mli
+++ b/utils/warnings.mli
@@ -26,6 +26,7 @@ type t = (* A is all *)
| Statement_type (* S *)
| Unused_match (* U *)
| Unused_pat
+ | Match_epsilon of string
| Hide_instance_variable of string (* V *)
| Illegal_backslash (* X *)
| Implicit_public_methods of string list