Browse Source

report Int | Int patterns as or-patterns to clarify errors (fixed issue #1415)

Simon Krajewski 12 years ago
parent
commit
30e5e28689
1 changed files with 9 additions and 1 deletions
  1. 9 1
      matcher.ml

+ 9 - 1
matcher.ml

@@ -78,6 +78,7 @@ type matcher = {
 	mutable subtrees : (int,dt) Hashtbl.t;
 	mutable num_subtrees : int;
 	mutable out_type : Type.t;
+	mutable toplevel_or : bool;
 }
 
 exception Not_exhaustive of pat * st
@@ -1059,12 +1060,14 @@ let match_expr ctx e cases def with_type p =
 		subtree_index = Hashtbl.create 0;
 		num_subtrees = 0;
 		out_type = mk_mono();
+		toplevel_or = false;
 	} in
 	let add_pattern_locals (pat,locals) =
 		PMap.iter (fun n (v,p) -> ctx.locals <- PMap.add n v ctx.locals) locals;
 		pat
 	in
 	let pl = ExtList.List.mapi (fun i (el,eg,e) ->
+		List.iter (fun e -> match fst e with EBinop(OpOr,_,_) -> mctx.toplevel_or <- true; | _ -> ()) el;
 		let ep = collapse_case el in
 		let save = save_locals ctx in
 		let pl = match tl with
@@ -1086,7 +1089,12 @@ let match_expr ctx e cases def with_type p =
 		if Common.defined ctx.com Define.MatchDebug then print_endline (s_dt "" dt);
 		PMap.iter (fun _ out -> if out.o_num_paths = 0 then begin
 			if out.o_pos == p then display_error ctx "The default pattern is unused" p
-			else display_error ctx "This pattern is unused" out.o_pos end) mctx.outcomes;
+			else display_error ctx "This pattern is unused" out.o_pos;
+			if mctx.toplevel_or then match evals with
+				| [{etype = t}] when (match follow t with TAbstract({a_path=[],"Int"},[]) -> true | _ -> false) ->
+					display_error ctx "Note: Int | Int is an or-pattern now" p;
+				| _ -> ()
+		end) mctx.outcomes;
 		let t = if not need_val then
 			mk_mono()
 		else