Browse Source

bugfix in enum matching

Nicolas Cannasse 17 years ago
parent
commit
a52b7f9750
2 changed files with 4 additions and 2 deletions
  1. 2 0
      typecore.ml
  2. 2 2
      typer.ml

+ 2 - 0
typecore.ml

@@ -58,6 +58,7 @@ type error_msg =
 	| Custom of string
 	| Protect of error_msg
 	| Unknown_ident of string
+	| Invalid_enum_matching
 	| Stack of error_msg * error_msg
 
 exception Error of error_msg * pos
@@ -88,6 +89,7 @@ let rec error_msg = function
 		let ctx = print_context() in
 		String.concat "\n" (List.map (unify_error_msg ctx) l)
 	| Unknown_ident s -> "Unknown identifier : " ^ s
+	| Invalid_enum_matching -> "Invalid enum matching case"
 	| Custom s -> s
 	| Stack (m1,m2) -> error_msg m1 ^ "\n" ^ error_msg m2
 	| Protect m -> error_msg m

+ 2 - 2
typer.ml

@@ -394,7 +394,7 @@ let type_constant ctx c p =
 	| Type _ -> assert false
 
 let type_matching ctx (enum,params) (e,p) ecases first_case =
-	let invalid() = error "Invalid enum matching" p in
+	let invalid() = raise (Error (Invalid_enum_matching,p)) in
 	let needs n = error ("This constructor needs " ^ string_of_int n ^ " parameters") p in
 	let constr name =
 		if PMap.mem name (!ecases) then error "This constructor has already been used" p;
@@ -823,7 +823,7 @@ and type_switch ctx e cases def need_val p =
 				(try
 					CMatch (type_matching ctx en e1 ecases !first_case)
 				with
-					Error _ when !first ->
+					Error (Invalid_enum_matching,_) when !first ->
 						enum := None;
 						type_case e e1)
 			| None ->