Forráskód Böngészése

deprecate using "is" as an identifier (#2976)

Aleksandr Kuzmenko 5 éve
szülő
commit
21530d939e

+ 5 - 1
src/context/display/deprecationCheck.ml

@@ -121,4 +121,8 @@ let run_on_expr ?(force=false) com e = if_enabled ~force com (fun() -> run_on_ex
 
 let run_on_field ?(force=false) com cf = if_enabled ~force com (fun() -> run_on_field com cf)
 
-let run ?(force=false) com = if_enabled ~force com (fun() -> run com)
+let run ?(force=false) com = if_enabled ~force com (fun() -> run com)
+
+let check_is com name p =
+	if name = "is" then
+		warn_deprecation com "Using \"is\" as an identifier is deprecated" p

+ 2 - 0
src/typing/typeloadFields.ml

@@ -546,6 +546,8 @@ let create_class_context ctx c context_init p =
 	ctx,cctx
 
 let create_field_context (ctx,cctx) c cff =
+	if c.cl_path <> ([],"Std") then
+		DeprecationCheck.check_is ctx.com (fst cff.cff_name) (snd cff.cff_name);
 	let ctx = {
 		ctx with
 		pass = PBuildClass; (* will be set later to PTypeExpr *)

+ 2 - 0
src/typing/typeloadModule.ml

@@ -195,6 +195,7 @@ let module_pass_1 ctx m tdecls loadp =
 	let decls = ref [] in
 	let statics = ref [] in
 	let check_name name p =
+		DeprecationCheck.check_is com name p;
 		let error prev_pos =
 			display_error ctx ("Name " ^ name ^ " is already defined in this module") p;
 			error (compl_msg "Previous declaration here") prev_pos;
@@ -441,6 +442,7 @@ let load_enum_field ctx e et is_flat index c =
 		ef_params = params;
 		ef_meta = c.ec_meta;
 	} in
+	DeprecationCheck.check_is ctx.com f.ef_name f.ef_name_pos;
 	let cf = {
 		(mk_field f.ef_name f.ef_type p f.ef_name_pos) with
 		cf_kind = (match follow f.ef_type with

+ 1 - 0
src/typing/typer.ml

@@ -1447,6 +1447,7 @@ and type_vars ctx vl p =
 	let vl = List.map (fun ev ->
 		let n = fst ev.ev_name
 		and pv = snd ev.ev_name in
+		DeprecationCheck.check_is ctx.com n pv;
 		try
 			let t = Typeload.load_type_hint ctx p ev.ev_type in
 			let e = (match ev.ev_expr with