Преглед изворни кода

[display] don't duplicate deprecation errors so much

closes #9192
Simon Krajewski пре 5 година
родитељ
комит
3c807297e1

+ 3 - 2
src/context/display/deprecationCheck.ml

@@ -8,8 +8,9 @@ let curclass = ref null_class
 let warned_positions = Hashtbl.create 0
 
 let warn_deprecation com s p_usage =
-	if not (Hashtbl.mem warned_positions p_usage) then begin
-		Hashtbl.replace warned_positions p_usage s;
+	let pkey p = (p.pfile,p.pmin) in
+	if not (Hashtbl.mem warned_positions (pkey p_usage)) then begin
+		Hashtbl.add warned_positions (pkey p_usage) (s,p_usage);
 		match com.display.dms_kind with
 		| DMDiagnostics _ -> ()
 		| _ -> com.warning s p_usage;

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

@@ -74,7 +74,7 @@ let json_of_diagnostics dctx =
 	List.iter (fun (s,p,prange) ->
 		add DKRemovableCode p DiagnosticsSeverity.Warning (JObject ["description",JString s;"range",if prange = null_pos then JNull else Genjson.generate_pos_as_range prange])
 	) dctx.removable_code;
-	Hashtbl.iter (fun p s ->
+	Hashtbl.iter (fun _ (s,p) ->
 		add DKDeprecationWarning p DiagnosticsSeverity.Warning (JString s);
 	) DeprecationCheck.warned_positions;
 	Hashtbl.iter (fun file ranges ->

+ 10 - 0
tests/misc/projects/Issue9192/Main.hx

@@ -0,0 +1,10 @@
+class Main {
+	static function main() {
+		A.field;
+	}
+}
+
+@:deprecated
+class A {
+	public static final field = 3;
+}

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

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

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

@@ -0,0 +1 @@
+Main.hx:3: characters 3-4 : Warning : Usage of this class is deprecated