Browse Source

[typer] bring back some deprecation checks that we forgot about

Simon Krajewski 2 years ago
parent
commit
e5405a82d8

+ 2 - 2
src/compiler/retyper.ml

@@ -130,7 +130,7 @@ let pair_classes rctx context_init c d p =
 			print_stack = (Printf.sprintf "[Field %s]" name) :: rctx.print_stack
 		} in
 		let display_modifier = Typeload.check_field_access ctx cff in
-		let fctx = create_field_context cctx cff ctx.is_display_file display_modifier in
+		let fctx = create_field_context ctx cctx cff ctx.is_display_file display_modifier in
 		let cf = match fctx.field_kind with
 			| FKConstructor ->
 				begin match c.cl_constructor with
@@ -196,7 +196,7 @@ let pair_abstracts ctx rctx context_init a d p =
 				print_stack = (Printf.sprintf "[Field %s]" name) :: rctx.print_stack
 			} in
 			let display_modifier = Typeload.check_field_access ctx cff in
-			let fctx = create_field_context cctx cff ctx.is_display_file display_modifier in
+			let fctx = create_field_context ctx cctx cff ctx.is_display_file display_modifier in
 			let cf = try
 				PMap.find name c.cl_statics
 			with Not_found ->

+ 1 - 1
src/context/display/displayTexpr.ml

@@ -64,7 +64,7 @@ let actually_check_display_field ctx c cff p =
 	let ctx = TypeloadFields.create_typer_context_for_class ctx cctx p in
 	let cff = TypeloadFields.transform_field (ctx,cctx) c cff (ref []) (pos cff.cff_name) in
 	let display_modifier = Typeload.check_field_access ctx cff in
-	let fctx = TypeloadFields.create_field_context cctx cff true display_modifier in
+	let fctx = TypeloadFields.create_field_context ctx cctx cff true display_modifier in
 	let cf = TypeloadFields.init_field (ctx,cctx,fctx) cff in
 	flush_pass ctx PTypeField "check_display_field";
 	ignore(follow cf.cf_type)

+ 0 - 2
src/core/define.ml

@@ -133,5 +133,3 @@ let deprecation_lut =
 		Hashtbl.add h name reason
 	) deprecated_defines;
 	h
-
-let is_haxe3_compat def = raw_defined def "hx3compat"

+ 6 - 0
src/core/meta.ml

@@ -120,3 +120,9 @@ let get_user_documentation_list user_metas =
 let copy_from_to m src dst =
 	try (get m src) :: dst
 	with Not_found -> dst
+
+let maybe_get_pos m ml = try
+		let (_,_,p) = get m ml in
+		Some p
+	with Not_found ->
+		None

+ 6 - 8
src/typing/typeloadFields.ml

@@ -523,8 +523,6 @@ let build_module_def ctx mt meta fvars context_init fbuild =
 	let f_enum = match mt with
 		| TClassDecl ({cl_kind = KAbstractImpl a} as c) when a.a_enum ->
 			Some (fun () ->
-				(* if p <> null_pos && not (Define.is_haxe3_compat ctx.com.defines) then
-					warning ctx WDeprecated "`@:enum abstract` is deprecated in favor of `enum abstract`" p; *)
 				context_init#run;
 				let e = build_enum_abstract ctx c a (fvars()) a.a_name_pos in
 				fbuild e;
@@ -596,7 +594,7 @@ let create_typer_context_for_class ctx cctx p =
 	} in
 	ctx
 
-let create_field_context cctx cff is_display_file display_modifier =
+let create_field_context ctx cctx cff is_display_file display_modifier =
 	let is_static = List.mem_assoc AStatic cff.cff_access in
 	let is_static,is_abstract_member = if cctx.abstract <> None && not is_static then true,true else is_static,false in
 	let is_extern = ref (List.mem_assoc AExtern cff.cff_access) in
@@ -606,11 +604,11 @@ let create_field_context cctx cff is_display_file display_modifier =
 		match m with
 		| Meta.Final ->
 			is_final := true;
-			(* if p <> null_pos && not (Define.is_haxe3_compat ctx.com.defines) then
-				warning ctx WDeprecated "`@:final` is deprecated in favor of `final`" p; *)
+			if p <> null_pos then
+				warning ctx WDeprecated "`@:final` is deprecated in favor of `final`" p;
 		| Meta.Extern ->
-			(* if not (Define.is_haxe3_compat ctx.com.defines) then
-				warning ctx WDeprecated "`@:extern` on fields is deprecated in favor of `extern`" (pos cff.cff_name); *)
+			if p <> null_pos then
+				warning ctx WDeprecated "`@:extern` is deprecated in favor of `extern`" p;
 			is_extern := true;
 		| _ ->
 			()
@@ -1787,7 +1785,7 @@ let init_class ctx c p context_init herits fields =
 		let p = f.cff_pos in
 		try
 			let display_modifier = Typeload.check_field_access ctx f in
-			let fctx = create_field_context cctx f ctx.is_display_file display_modifier in
+			let fctx = create_field_context ctx cctx f ctx.is_display_file display_modifier in
 			let ctx = create_typer_context_for_field ctx cctx fctx f in
 			if fctx.is_field_debug then print_endline ("Created field context: " ^ dump_field_context fctx);
 			let cf = init_field (ctx,cctx,fctx) f in

+ 7 - 2
src/typing/typeloadModule.ml

@@ -175,6 +175,7 @@ module ModuleLevel = struct
 				check_type_name name d.d_meta;
 				let priv = List.mem AbPrivate d.d_flags in
 				let path = make_path name priv d.d_meta p in
+				let p_enum_meta = Meta.maybe_get_pos Meta.Enum d.d_meta in
 				let a = {
 					a_path = path;
 					a_private = priv;
@@ -198,9 +199,13 @@ module ModuleLevel = struct
 					a_read = None;
 					a_write = None;
 					a_call = None;
-					a_enum = List.mem AbEnum d.d_flags || Meta.has Meta.Enum d.d_meta;
+					a_enum = List.mem AbEnum d.d_flags || p_enum_meta <> None;
 				} in
-				if a.a_enum && not (Meta.has Meta.Enum a.a_meta) then a.a_meta <- (Meta.Enum,[],null_pos) :: a.a_meta;
+				begin match p_enum_meta with
+					| None when a.a_enum -> a.a_meta <- (Meta.Enum,[],null_pos) :: a.a_meta; (* HAXE5: remove *)
+					| None -> ()
+					| Some p -> warning ctx WDeprecated "`@:enum abstract` is deprecated in favor of `enum abstract`" p
+				end;
 				decls := (TAbstractDecl a, decl) :: !decls;
 				match d.d_data with
 				| [] when Meta.has Meta.CoreType a.a_meta ->

+ 5 - 5
tests/unit/src/unit/issues/Issue9771.hx

@@ -1,10 +1,10 @@
 package unit.issues;
 
 private abstract Continue(Dynamic) {
-	@:commutative @:op(a+b)
-	@:extern static inline function then<A>(e:Continue, a:A):A
-	  return a;
-  }
+	@:commutative @:op(a + b)
+	extern static inline function then<A>(e:Continue, a:A):A
+		return a;
+}
 
 class Issue9771 extends unit.Test {
 	var buf:StringBuf;
@@ -36,4 +36,4 @@ class Issue9771 extends unit.Test {
 		bar = "bar";
 		eq('bar', bar + append('foo'));
 	}
-}
+}