From e74551e8ee5b3ea2eb120c2bfcaea92ca8940c9e Mon Sep 17 00:00:00 2001
From: Erwan Jahier <erwan.jahier@univ-grenoble-alpes.fr>
Date: Thu, 22 Jun 2017 08:58:07 +0200
Subject: [PATCH] Better error messages.

---
 _oasis             |  2 +-
 src/evalType.ml    | 19 +++++++++++--------
 src/licEvalType.ml | 15 +++++++--------
 src/lv6version.ml  |  4 ++--
 test/lus2lic.sum   | 24 ++++++++++++------------
 5 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/_oasis b/_oasis
index 5680c160..61f9e243 100644
--- a/_oasis
+++ b/_oasis
@@ -1,6 +1,6 @@
 OASISFormat: 0.4
 Name:        lustre-v6
-Version:     1.697
+Version:     1.698
 Synopsis:    The Lustre V6 Verimag compiler
 Description: This package contains:
    (1) lus2lic: the (current) name of the compiler (and interpreter via -exec).
diff --git a/src/evalType.ml b/src/evalType.ml
index 3562b111..38fd48da 100644
--- a/src/evalType.ml
+++ b/src/evalType.ml
@@ -1,4 +1,4 @@
-(** Time-stamp: <modified the 24/11/2016 (at 16:25) by Erwan Jahier> *)
+(** Time-stamp: <modified the 22/06/2017 (at 08:43) by Erwan Jahier> *)
  
   
 open AstPredef
@@ -89,7 +89,7 @@ and eval_by_pos_type
       let t_args = List.flatten t_argsl in
       let llti = List.length lti and lt_args = List.length t_args in
       let _ = if llti <> lt_args then
-          raise_arity_error "" lt_args llti
+          raise_arity_error (fst (fst node_key)) lt_args llti
       in
       (* lti = expecteds, t_args = given *)
       let tmatches = try UnifyType.is_matched lti t_args 
@@ -138,8 +138,11 @@ and eval_by_pos_type
           else
             raise_type_error (List.flatten targs) []
               "two arrays of the same type was expected"
+        | [ t1;t2 ] ->
+           raise_type_error (List.flatten targs) []
+                            "             whereas 2 arrays were expected"
         | _ -> 
-          raise_arity_error "" (List.length args) 2
+          raise_arity_error "concat" (List.length args) 2
       in
       None, args, tve
     | Lic.STRUCT_ACCESS (fid) ->
@@ -157,7 +160,7 @@ and eval_by_pos_type
                      (Lic.string_of_type (List.hd targ))))
           )
           | [x] -> raise_type_error [x] [] "some struct type was expected"
-          |  x -> raise_arity_error "" (List.length x) 1 
+          |  x -> raise_arity_error "struct access" (List.length x) 1 
       in
       None, [arg], [teff_field]
     | Lic.ARRAY_ACCES(i) ->
@@ -244,7 +247,7 @@ and eval_by_pos_type
       in
       match targs with
         | [teff] -> None, args, teff
-        | _ -> raise_arity_error "" (List.length targs) 1 
+        | _ -> raise_arity_error "when" (List.length targs) 1 
     )
     | Lic.ARROW
     | Lic.FBY -> (
@@ -252,20 +255,20 @@ and eval_by_pos_type
       match targs with
         | [init; teff] -> if init = teff then None, args, teff else 
             raise(EvalType_error("type mismatch. "))
-        | _ -> raise_arity_error "" (List.length targs) 2
+        | _ -> raise_arity_error "fby" (List.length targs) 2
     )
     | Lic.CURRENT (Some _) -> (
       let args, targs = List.split (List.map (f id_solver) args) in
       match targs with
         | [_;teff] -> None, args, teff
-        | _ -> raise_arity_error "" (List.length targs) 2
+        | _ -> raise_arity_error "current" (List.length targs) 2
     )
     | Lic.CURRENT None
     | Lic.PRE -> (
       let args, targs = List.split (List.map (f id_solver) args) in
       match targs with
         | [teff] -> None, args, teff
-        | _ -> raise_arity_error "" (List.length targs) 1
+        | _ -> raise_arity_error "pre" (List.length targs) 1
     )
 
 
diff --git a/src/licEvalType.ml b/src/licEvalType.ml
index 5666cbb7..1d39be53 100644
--- a/src/licEvalType.ml
+++ b/src/licEvalType.ml
@@ -1,4 +1,4 @@
-(* Time-stamp: <modified the 30/11/2016 (at 16:40) by Erwan Jahier> *)
+(* Time-stamp: <modified the 22/06/2017 (at 08:40) by Erwan Jahier> *)
 
 open AstPredef
 open Lxm
@@ -32,9 +32,8 @@ let raise_type_error
       let pr = Lic.string_of_type_list prov in
       let ex = Lic.string_of_type_list expec in
       (
-        "\n*** type '" ^ pr ^ "' was provided" ^ (
-          if ex = "" then "" 
-          else (" whereas\n*** type '" ^ex^"' was expected")
+        "'" ^ pr ^ "' was provided" ^ (
+          if ex = "" then "" else (" whereas\n*** type '" ^ex^"' was expected")
         ) ^ (
           if msg = "" then "" else ("\n*** " ^ msg)
         )
@@ -44,7 +43,7 @@ let raise_type_error
 
 let raise_arity_error (msg:string) (get:int) (expect:int) =
   raise (EvalType_error(
-    Printf.sprintf "\n*** arity error%s: %d argument%s, whereas %d were expected"
+    Printf.sprintf "bad arity (%s): %d argument%s, whereas %d were expected"
       msg get (if get>1 then "s" else "") expect))
 
 (*********************************************************************************)
@@ -150,7 +149,7 @@ let condact_profile
         Lv6Verbose.exe ~flag:dbg ~level:3  (fun () ->
           Lv6Verbose.printf "  condact_profile: dflt=%s\n" (string_of_const_eff dflt));
     let _ = if (dl <> ol) then
-        raise_arity_error " in condact default arg" dl ol in
+        raise_arity_error "in condact default arg" dl ol in
     let out_types = List.map (fun x -> x.var_type_eff) outlist in
 
     let _ = if dflt_types <> out_types then
@@ -390,7 +389,7 @@ let f (id_solver: IdSolver.t) (op: op) (lxm: Lxm.t) : typer = fun ll ->
             | [[Bool_type_eff]; t; e] -> 
               if t = e then t else 
                 (type_error (List.flatten [[Bool_type_eff]; t; e]) "bool*any*any")
-            | x -> (raise_arity_error "" (List.length x) 3)
+            | x -> (raise_arity_error "if/then/else" (List.length x) 3)
         )
         | (NOR_n | DIESE_n) -> 
           (* VERRUE 2 : cannot check the arity for them. *)
@@ -409,7 +408,7 @@ let f (id_solver: IdSolver.t) (op: op) (lxm: Lxm.t) : typer = fun ll ->
           and lto = List.map (fun v -> v.var_type_eff) node_eff.outlist_eff in
           let l = List.flatten ll in
           if (List.length l <> List.length lti) then
-            raise_arity_error "" (List.length l) (List.length lti)
+            raise_arity_error (op2string op) (List.length l) (List.length lti)
           else if (l = []) then
             (* useless to call UnifyType.f ! *)
             lto
diff --git a/src/lv6version.ml b/src/lv6version.ml
index 398da26f..41c36ab5 100644
--- a/src/lv6version.ml
+++ b/src/lv6version.ml
@@ -1,7 +1,7 @@
 (** Automatically generated from Makefile *) 
 let tool = "lus2lic"
 let branch = "master"
-let commit = "697"
-let sha_1 = "2650f12bcd544dc9b308b2ffb31f2a4a7267bbcb"
+let commit = "698"
+let sha_1 = "6e914d041797511cf84b2a956827d355630bd3fc"
 let str = (branch ^ "." ^ commit ^ " (" ^ sha_1 ^ ")")
 let maintainer = "jahier@imag.fr"
diff --git a/test/lus2lic.sum b/test/lus2lic.sum
index 2e94ac9f..eeb9c1d5 100644
--- a/test/lus2lic.sum
+++ b/test/lus2lic.sum
@@ -1,5 +1,5 @@
 ==> lus2lic0.sum <==
-Test Run By jahier on Wed Jun 21 17:15:56 
+Test Run By jahier on Thu Jun 22 08:46:40 
 Native configuration is x86_64-unknown-linux-gnu
 
 		=== lus2lic0 tests ===
@@ -64,7 +64,7 @@ XFAIL: Test bad programs (assert): test_lus2lic_no_node should_fail/assert/lecte
 XFAIL: Test bad programs (assert): test_lus2lic_no_node should_fail/assert/s.lus
 
 ==> lus2lic1.sum <==
-Test Run By jahier on Wed Jun 21 17:15:57 
+Test Run By jahier on Thu Jun 22 08:46:41 
 Native configuration is x86_64-unknown-linux-gnu
 
 		=== lus2lic1 tests ===
@@ -398,7 +398,7 @@ PASS: sh multipar.sh
 PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c multipar.lus  {}
 
 ==> lus2lic2.sum <==
-Test Run By jahier on Wed Jun 21 17:16:53 
+Test Run By jahier on Thu Jun 22 08:47:32 
 Native configuration is x86_64-unknown-linux-gnu
 
 		=== lus2lic2 tests ===
@@ -738,7 +738,7 @@ PASS: sh zzz2.sh
 PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c zzz2.lus  {}
 
 ==> lus2lic3.sum <==
-Test Run By jahier on Wed Jun 21 17:17:49 
+Test Run By jahier on Thu Jun 22 08:48:28 
 Native configuration is x86_64-unknown-linux-gnu
 
 		=== lus2lic3 tests ===
@@ -1243,7 +1243,7 @@ PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node multipar.lus {}
 
 
 ==> lus2lic4.sum <==
-Test Run By jahier on Wed Jun 21 17:19:06 
+Test Run By jahier on Thu Jun 22 08:49:40 
 Native configuration is x86_64-unknown-linux-gnu
 
 		=== lus2lic4 tests ===
@@ -1760,14 +1760,14 @@ PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node zzz2.lus {}
 # of unexpected failures	6
 ===============================
 # Total number of failures: 22
-lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 1 seconds
+lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 0 seconds
 lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 51 seconds
-lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 56 seconds
+lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 55 seconds
 lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 72 seconds
-lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 48 seconds
+lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 49 seconds
 * Ref time: 
-0.06user 0.00system 3:58.30elapsed 0%CPU (0avgtext+0avgdata 5688maxresident)k
-96inputs+0outputs (0major+6157minor)pagefaults 0swaps
+0.07user 0.00system 3:49.41elapsed 0%CPU (0avgtext+0avgdata 5628maxresident)k
+64inputs+0outputs (0major+6184minor)pagefaults 0swaps
 * Quick time (-j 4):
-0.04user 0.04system 2:19.84elapsed 0%CPU (0avgtext+0avgdata 5684maxresident)k
-32inputs+0outputs (0major+6176minor)pagefaults 0swaps
+0.06user 0.01system 2:20.88elapsed 0%CPU (0avgtext+0avgdata 5628maxresident)k
+64inputs+0outputs (0major+6181minor)pagefaults 0swaps
-- 
GitLab