From 986448c60aafcd840959fa3a78ae9995c5ec229e Mon Sep 17 00:00:00 2001
From: Thomas Wood <thomas.wood09@imperial.ac.uk>
Date: Wed, 23 Sep 2015 13:00:58 +0100
Subject: [PATCH] Less ambiguous "Ambiguities when applying constructor" error

---
 generator/js_of_ast.ml | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/generator/js_of_ast.ml b/generator/js_of_ast.ml
index 7863a5e..91ddafd 100644
--- a/generator/js_of_ast.ml
+++ b/generator/js_of_ast.ml
@@ -271,9 +271,10 @@ let find_type name =
   let tmp = Hashtbl.find_all type_tbl short_name in
   let candidates = if List.length tmp = 1 then tmp else List.filter (fun (x, _) -> filter_on_prefixes prefixes (short_name :: x)) tmp in
     (* print_string @@ print_candidates @@ (Hashtbl.find_all type_tbl short_name); print_newline (); *)
-  if List.length candidates = 1
-  then snd @@ List.hd candidates
-  else failwith ("ambiguity when applying constructor " ^ name)
+  match candidates with
+  | [] -> print_type_tbl (); failwith ("no options for constructor " ^ name)
+  | c :: [] -> snd c
+  | _ -> print_type_tbl (); failwith ("ambiguity when applying constructor " ^ name)
 
 (**
  * Module managment part
-- 
GitLab