Skip to content

Commit

Permalink
Implement rejection of functions with duplicate parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
0npv527yh9 committed Oct 23, 2023
1 parent c7f3094 commit f5748b7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/simpleChecker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f5748b7

Please sign in to comment.