Nicolas Cannasse 19 роки тому
батько
коміт
97b6da28b2
2 змінених файлів з 8 додано та 2 видалено
  1. 4 0
      main.ml
  2. 4 2
      typer.ml

+ 4 - 0
main.ml

@@ -132,6 +132,7 @@ try
 	let cmds = ref [] in
 	let excludes = ref [] in
 	Plugin.defines := base_defines;
+	Typer.check_override := false;
 	Typer.forbidden_packages := ["js"; "neko"; "flash"];
 	Parser.display_error := parse_error;
 	(try
@@ -228,6 +229,9 @@ try
 			cmds := cmd :: !cmds
 		),": run the specified command after successful compilation");
 		("--flash-strict", define "flash_strict", ": more type strict flash API");
+		("--override", Arg.Unit (fun() -> 
+			Typer.check_override := true
+		),": ensure that overriden methods are declared with 'override'");
 		("--no-traces", define "no_traces", ": don't compile trace calls in the program");
 		("--flash-use-stage", define "flash_use_stage", ": place objects found on the stage of the SWF lib");
 		("--next", Arg.Unit (fun() -> assert false), ": separate several haxe compilations");

+ 4 - 2
typer.ml

@@ -97,6 +97,7 @@ let rec error_msg = function
 	| Protect m -> error_msg m
 
 let forbidden_packages = ref []
+let check_override = ref false
 
 let error msg p = raise (Error (Custom msg,p))
 
@@ -1758,7 +1759,7 @@ let check_overriding ctx c p () =
 				let t = apply_params csup.cl_types params t in
 				ignore(follow f.cf_type); (* force evaluation *)
 				let p = (match f.cf_expr with None -> p | Some e -> e.epos) in
-				if not (List.mem i c.cl_overrides) then 
+				if !check_override && not (List.mem i c.cl_overrides) then
 					display_error ctx ("Field " ^ i ^ " should be declared with 'override' since it is inherited from superclass") p
 				else if f.cf_public <> f2.cf_public then
 					display_error ctx ("Field " ^ i ^ " has different visibility (public/private) than superclass one") p
@@ -1767,7 +1768,8 @@ let check_overriding ctx c p () =
 				else if not (type_eq false (field_type f) t) then
 					display_error ctx ("Field " ^ i ^ " overload parent class with different or incomplete type") p
 			with
-				Not_found -> ()
+				Not_found ->
+					if List.mem i c.cl_overrides then display_error ctx ("Field " ^ i ^ " is declared 'override' but doesn't override any field") p
 		) c.cl_fields
 
 let rec check_interface ctx c p intf params =