Browse Source

- fix `@:deprecated` description
- push `@:deprecated` to abstract implementation
- push `@:deprecated` on property fields to accessor fields

closes #4720

Simon Krajewski 9 years ago
parent
commit
de499fcf80

+ 1 - 1
common.ml

@@ -392,7 +392,7 @@ module MetaInfo = struct
 		| DefParam -> ":defParam",("?",[])
 		| Delegate -> ":delegate",("Automatically added by -net-lib on delegates",[Platform Cs; UsedOn TAbstract])
 		| Depend -> ":depend",("",[Platform Cpp])
-		| Deprecated -> ":deprecated",("Automatically added by -java-lib on class fields annotated with @Deprecated annotation. Has no effect on types compiled by Haxe",[Platform Java; UsedOnEither [TClass;TEnum;TClassField]])
+		| Deprecated -> ":deprecated",("Mark a type or field as deprecated",[])
 		| DirectlyUsed -> ":directlyUsed",("Marks types that are directly referenced by non-extern code",[Internal])
 		| DynamicObject -> ":dynamicObject",("Used internally to identify the Dynamic Object implementation",[Platforms [Java;Cs]; UsedOn TClass; Internal])
 		| Enum -> ":enum",("Defines finite value sets to abstract definitions",[UsedOn TAbstract])

+ 70 - 0
tests/misc/projects/Issue4720/Main.hx

@@ -0,0 +1,70 @@
+class Main {
+    static function main() {
+        // deprecating type objects work
+        MyClass;
+        MyInterface;
+        MyEnum;
+        // MyAbstract; // this compiles when analyzer=yes, but is another issue
+        TClass;
+        TInterface;
+        TEnum;
+        // TAbstract;  // this compiles when analyzer=yes, but is another issue
+        // TAnon; // this won't and shouldn't compile anyway
+
+        // deprecating types instantiated work
+        new MyClass();
+        MyEnum.None;
+        new MyAbstract(null); // but doesn't work on abstracts...
+        new TClass();
+        TEnum.None;
+        new TAbstract(null); // neither
+
+        // some physical access to deprecated API
+        deprecatedField;
+        deprecatedFunc();
+        deprecatedProperty; // this won't show warnings
+        var x = deprecatedProperty; // this also
+        deprecatedGetSet; // however this will
+        var x = deprecatedGetSet; // this also
+    }
+
+    // deprecating fields work
+    @:deprecated static var deprecatedField:String;
+    @:deprecated static function deprecatedFunc() return;
+
+    // ... however deprecating getters and setters have some gotcha
+    @:deprecated static var deprecatedProperty(get, set):String;
+    static function get_deprecatedProperty():String return "0";
+    static function set_deprecatedProperty(value):String return "0";
+
+    static var deprecatedGetSet(get, set):String;
+    @:deprecated static function get_deprecatedGetSet():String return "0";
+    @:deprecated static function set_deprecatedGetSet(value):String return "0";
+}
+
+@:deprecated
+class MyClass { public function new() {} }
+
+@:deprecated
+interface MyInterface { }
+
+@:deprecated
+enum MyEnum { None; }
+
+@:deprecated
+abstract MyAbstract(String) { public function new(value:String) this = value; }
+
+@:deprecated
+typedef TClass = MyClass;
+
+@:deprecated
+typedef TInterface = MyInterface;
+
+@:deprecated
+typedef TEnum = MyEnum;
+
+@:deprecated
+typedef TAbstract = MyAbstract;
+
+@:deprecated
+typedef TAnon = { a:String };

+ 2 - 0
tests/misc/projects/Issue4720/compile.hxml

@@ -0,0 +1,2 @@
+-main Main
+--interp

+ 18 - 0
tests/misc/projects/Issue4720/compile.hxml.stderr

@@ -0,0 +1,18 @@
+Main.hx:8: characters 8-14 : Warning : Usage of this typedef is deprecated
+Main.hx:9: characters 8-18 : Warning : Usage of this typedef is deprecated
+Main.hx:10: characters 8-13 : Warning : Usage of this typedef is deprecated
+Main.hx:19: characters 8-18 : Warning : Usage of this typedef is deprecated
+Main.hx:4: characters 8-15 : Warning : Usage of this class is deprecated
+Main.hx:5: characters 8-19 : Warning : Usage of this class is deprecated
+Main.hx:6: characters 8-14 : Warning : Usage of this enum is deprecated
+Main.hx:15: characters 8-21 : Warning : Usage of this class is deprecated
+Main.hx:16: characters 8-19 : Warning : Usage of this enum is deprecated
+Main.hx:17: characters 8-28 : Warning : Usage of this class is deprecated
+Main.hx:18: characters 8-20 : Warning : Usage of this class is deprecated
+Main.hx:20: characters 8-27 : Warning : Usage of this class is deprecated
+Main.hx:23: characters 8-23 : Warning : Usage of this field is deprecated
+Main.hx:24: characters 8-22 : Warning : Usage of this field is deprecated
+Main.hx:25: characters 8-26 : Warning : Usage of this field is deprecated
+Main.hx:26: characters 16-34 : Warning : Usage of this field is deprecated
+Main.hx:27: characters 8-24 : Warning : Usage of this field is deprecated
+Main.hx:28: characters 16-32 : Warning : Usage of this field is deprecated

+ 5 - 1
typeload.ml

@@ -199,7 +199,7 @@ let module_pass_1 com m tdecls loadp =
 				(match !decls with
 				| (TClassDecl c,_) :: _ ->
 					List.iter (fun m -> match m with
-						| ((Meta.Build | Meta.CoreApi | Meta.Allow | Meta.Access | Meta.Enum | Meta.Dce | Meta.Native | Meta.Expose),_,_) ->
+						| ((Meta.Build | Meta.CoreApi | Meta.Allow | Meta.Access | Meta.Enum | Meta.Dce | Meta.Native | Meta.Expose | Meta.Deprecated),_,_) ->
 							c.cl_meta <- m :: c.cl_meta;
 						| _ ->
 							()
@@ -2554,6 +2554,10 @@ module ClassInitializer = struct
 				if (fctx.is_abstract_member && not (Meta.has Meta.Impl f2.cf_meta)) || (Meta.has Meta.Impl f2.cf_meta && not (fctx.is_abstract_member)) then
 					display_error ctx "Mixing abstract implementation and static properties/accessors is not allowed" f2.cf_pos;
 				(match req_name with None -> () | Some n -> display_error ctx ("Please use " ^ n ^ " to name your property access method") f2.cf_pos);
+				f2.cf_meta <- List.fold_left (fun acc ((m,_,_) as meta) -> match m with
+					| Meta.Deprecated -> meta :: acc
+					| _ -> acc
+				) f2.cf_meta f.cff_meta;
 			with
 				| Error (Unify l,p) -> raise (Error (Stack (Custom ("In method " ^ m ^ " required by property " ^ f.cff_name),Unify l),p))
 				| Not_found ->