Просмотр исходного кода

[display] don't diagnostics so much if there are errors

closes #10194
Simon Krajewski 4 лет назад
Родитель
Сommit
adf74211ff

+ 15 - 11
src/context/display/diagnostics.ml

@@ -97,16 +97,8 @@ let prepare_field dctx com cf = match cf.cf_expr with
 		check_other_things com e;
 		DeprecationCheck.run_on_expr ~force:true com e
 
-let prepare com =
-	let dctx = {
-		removable_code = [];
-		import_positions = PMap.empty;
-		dead_blocks = Hashtbl.create 0;
-		diagnostics_messages = [];
-		unresolved_identifiers = [];
-		missing_fields = PMap.empty;
-	} in
-	List.iter (function
+let collect_diagnostics dctx com =
+		List.iter (function
 		| TClassDecl c when DiagnosticsPrinter.is_diagnostics_file (com.file_keys#get c.cl_pos.pfile) ->
 			List.iter (prepare_field dctx com) c.cl_ordered_fields;
 			List.iter (prepare_field dctx com) c.cl_ordered_statics;
@@ -137,7 +129,19 @@ let prepare com =
 		| None ->
 			()
 	in
-	handle_dead_blocks com;
+	handle_dead_blocks com
+
+let prepare com =
+	let dctx = {
+		removable_code = [];
+		import_positions = PMap.empty;
+		dead_blocks = Hashtbl.create 0;
+		diagnostics_messages = [];
+		unresolved_identifiers = [];
+		missing_fields = PMap.empty;
+	} in
+	if not (List.exists (fun (_,_,_,sev) -> sev = DiagnosticsSeverity.Error) com.shared.shared_display_information.diagnostics_messages) then
+		collect_diagnostics dctx com;
 	let process_modules com =
 		List.iter (fun m ->
 			PMap.iter (fun p b ->

+ 22 - 0
tests/display/src/cases/Issue10194.hx

@@ -0,0 +1,22 @@
+package cases;
+
+class Issue10194 extends DisplayTestCase {
+	/**
+		function f(a:Int, b:Int) {}
+
+		function main() {
+			var v = 10; // reported as "unused variable"
+			f({-1-}""{-2-}, v);
+		}
+	**/
+	function test() {
+		arrayEq([
+			{
+				kind: DKCompilerError,
+				severity: Error,
+				range: diagnosticsRange(pos(1), pos(2)),
+				args: "String should be Int\nFor function argument 'a'"
+			}
+		], diagnostics());
+	}
+}

+ 1 - 7
tests/display/src/cases/Issue5306.hx

@@ -7,7 +7,7 @@ class Issue5306 extends DisplayTestCase {
 		class Main {
 			static function main() {
 				var ib:Array<Int>;
-				ib[0] = 0; ib[1] = 1; {-7-}ib[2]{-8-}
+				ib[0] = 0; ib[1] = 1; ib[2]
 				{-5-}trace{-6-}("test");
 			}
 		}
@@ -31,12 +31,6 @@ class Issue5306 extends DisplayTestCase {
 				range: diagnosticsRange(pos(5), pos(6)),
 				severity: Error,
 				args: "Missing ;"
-			},
-			{
-				kind: DKCompilerError,
-				range: diagnosticsRange(pos(7), pos(8)),
-				severity: Warning,
-				args: "This code has no effect"
 			}
 		];
 		arrayEq(expected, diagnostics());

+ 0 - 12
tests/display/src/cases/Issue7943.hx

@@ -15,18 +15,6 @@ class Issue7943 extends DisplayTestCase {
 				severity: Error,
 				range: diagnosticsRange(pos(3), pos(4)),
 				args: "Missing ;"
-			},
-			{
-				kind: DKCompilerError,
-				severity: Warning,
-				range: diagnosticsRange(pos(3), pos(4)),
-				args: "This code has no effect"
-			},
-			{
-				kind: DKCompilerError,
-				severity: Warning,
-				range: diagnosticsRange(pos(1), pos(2)),
-				args: "This code has no effect"
 			}
 		], diagnostics());
 	}