Procházet zdrojové kódy

[matcher] print deprecation messages for enum (fields) (closes #6485)

Simon Krajewski před 8 roky
rodič
revize
fed4f23652

+ 7 - 2
src/typing/matcher.ml

@@ -186,12 +186,17 @@ module Pattern = struct
 				ctx.locals <- PMap.add name v ctx.locals;
 				v
 		in
+		let con_enum en ef p =
+			Display.DeprecationCheck.check_enum pctx.ctx.com en p;
+			Display.DeprecationCheck.check_ef pctx.ctx.com ef p;
+			ConEnum(en,ef)
+		in
 		let check_expr e =
 			let rec loop e = match e.eexpr with
 				| TField(_,FEnum(en,ef)) ->
 					(* Let the unification afterwards fail so we don't recover. *)
 					(* (match follow ef.ef_type with TFun _ -> raise Exit | _ -> ()); *)
-					PatConstructor(ConEnum(en,ef),[])
+					PatConstructor(con_enum en ef e.epos,[])
 				| TField(_,FStatic(c,({cf_kind = Var {v_write = AccNever}} as cf))) ->
 					PatConstructor(ConStatic(c,cf),[])
 				| TConst ct ->
@@ -322,7 +327,7 @@ module Pattern = struct
 						(* We want to change the original monomorphs back to type parameters, but we don't want to do that
 						   if they are bound to other monomorphs (issue #4578). *)
 						unapply_type_parameters ef.ef_params monos;
-						PatConstructor(ConEnum(en,ef),patterns)
+						PatConstructor(con_enum en ef e1.epos,patterns)
 					| _ ->
 						fail()
 				end

+ 12 - 1
tests/misc/projects/Issue4720/Main.hx

@@ -26,6 +26,15 @@ class Main {
         var x = deprecatedProperty; // this also
         deprecatedGetSet; // however this will
         var x = deprecatedGetSet; // this also
+
+		// the enum @:deprecated trumps the enum field one... should be fine
+		switch (None) {
+			case None:
+		}
+
+		switch (None2) {
+			case None2:
+		}
     }
 
     // deprecating fields work
@@ -49,7 +58,9 @@ class MyClass { public function new() {} }
 interface MyInterface { }
 
 @:deprecated
-enum MyEnum { None; }
+enum MyEnum { @:deprecated None; }
+
+enum MyEnum2 { @:deprecated None2; }
 
 @:deprecated
 abstract MyAbstract(String) { public function new(value:String) this = value; }

+ 5 - 1
tests/misc/projects/Issue4720/compile.hxml.stderr

@@ -2,6 +2,8 @@ Main.hx:8: characters 9-15 : Warning : Usage of this typedef is deprecated
 Main.hx:9: characters 9-19 : Warning : Usage of this typedef is deprecated
 Main.hx:10: characters 9-14 : Warning : Usage of this typedef is deprecated
 Main.hx:19: characters 9-19 : Warning : Usage of this typedef is deprecated
+Main.hx:32: characters 9-13 : Warning : Usage of this enum is deprecated
+Main.hx:36: characters 9-14 : Warning : Usage of this enum field is deprecated
 Main.hx:4: characters 9-16 : Warning : Usage of this class is deprecated
 Main.hx:5: characters 9-20 : Warning : Usage of this class is deprecated
 Main.hx:6: characters 9-15 : Warning : Usage of this enum is deprecated
@@ -15,4 +17,6 @@ Main.hx:24: characters 9-23 : Warning : Usage of this field is deprecated
 Main.hx:25: characters 9-27 : Warning : Usage of this field is deprecated
 Main.hx:26: characters 17-35 : Warning : Usage of this field is deprecated
 Main.hx:27: characters 9-25 : Warning : Usage of this field is deprecated
-Main.hx:28: characters 17-33 : Warning : Usage of this field is deprecated
+Main.hx:28: characters 17-33 : Warning : Usage of this field is deprecated
+Main.hx:31: characters 11-15 : Warning : Usage of this enum is deprecated
+Main.hx:35: characters 11-16 : Warning : Usage of this enum field is deprecated