Browse Source

emit deprecation warning on matching with a deprecated inline var (#9204)

Aleksandr Kuzmenko 5 năm trước cách đây
mục cha
commit
ff7406c5d9

+ 3 - 2
src/typing/matcher.ml

@@ -234,8 +234,9 @@ module Pattern = struct
 					raise (Bad_pattern "Only inline or read-only (default, never) fields can be used as a pattern")
 				| TTypeExpr mt ->
 					PatConstructor(con_type_expr mt e.epos,[])
-				| TMeta((Meta.Deprecated,_,_), e) ->
-					loop e
+				| TMeta((Meta.Deprecated,_,_) as m, e1) ->
+					DeprecationCheck.check_meta pctx.ctx.com [m] "field" e1.epos;
+					loop e1
 				| _ ->
 					raise Exit
 			in

+ 20 - 0
tests/misc/projects/Issue9204/Main.hx

@@ -0,0 +1,20 @@
+class C {
+	@:deprecated
+	static inline final SOME = 1;
+
+	static public function f(x:Int) {
+		switch (x) {
+			case SOME:
+				trace(1);
+			case _:
+				trace(2);
+		}
+	}
+}
+
+class Main {
+	static function main() {
+		C.f(1);
+		C.f(2);
+	}
+}

+ 1 - 0
tests/misc/projects/Issue9204/compile.hxml

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

+ 1 - 0
tests/misc/projects/Issue9204/compile.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:7: characters 9-13 : Warning : Usage of this field is deprecated