From f5748b7db4ffd069c2b963c9dc7fe61c3d1e9867 Mon Sep 17 00:00:00 2001 From: Junya Hirashima Date: Tue, 24 Oct 2023 01:59:23 +0900 Subject: [PATCH 1/2] Implement rejection of functions with duplicate parameters --- src/simpleChecker.ml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/simpleChecker.ml b/src/simpleChecker.ml index 9a1c838c..baf4d38a 100644 --- a/src/simpleChecker.ml +++ b/src/simpleChecker.ml @@ -167,11 +167,25 @@ let abstract_type sub_ctxt t = in loop t +let find_opt_duplicate_vars vars = + let sorted_vars = List.fast_sort String.compare vars in + let rec find_dup l = match l with + | [_] + | [] -> None + | h::h'::_ when h = h' -> Some h + | _::t -> find_dup t + in + find_dup sorted_vars + let make_fenv uf fns = List.fold_left (fun acc {name; args; _} -> if StringMap.mem name acc then failwith @@ "Duplicate function definitions for: " ^ name else + match find_opt_duplicate_vars args with + | Some v -> failwith @@ "Duplicate parameters of function " ^ name ^ ": " ^ v + | _ -> (); + StringMap.add name { arg_types_v = List.map (fun _ -> UnionFind.new_node uf) args; ret_type_v = UnionFind.new_node uf From 1e4859acec133dd1d6156bc6ab34e39087d02c9b Mon Sep 17 00:00:00 2001 From: Junya Hirashima Date: Tue, 24 Oct 2023 02:07:09 +0900 Subject: [PATCH 2/2] Improve error messages for function calls with duplicate arguments --- src/simpleChecker.ml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/simpleChecker.ml b/src/simpleChecker.ml index baf4d38a..abc78fdd 100644 --- a/src/simpleChecker.ml +++ b/src/simpleChecker.ml @@ -343,15 +343,11 @@ let rec resolve_with_rec sub v_set k t = ) t' let process_call ~loc lkp ctxt { callee; arg_names; _ } = - let sorted_args = List.fast_sort String.compare arg_names in - let rec find_dup l = match l with - | [_] - | [] -> false - | h::h'::_ when h = h' -> true - | _::t -> find_dup t - in - if find_dup sorted_args then - failwith "Duplicate variable names detected"; + match find_opt_duplicate_vars arg_names with + | Some v -> + Locations.raise_errorf ~loc "Duplicate arguments in function %s call: %s" callee v + | _ -> (); + let { arg_types_v; ret_type_v } = try StringMap.find callee ctxt.fenv