Browse Source

[display] don't show Void-returners in value places

Simon Krajewski 7 years ago
parent
commit
ed4e718bb2
2 changed files with 31 additions and 6 deletions
  1. 8 4
      src/typing/typerDisplay.ml
  2. 23 2
      tests/display/src/cases/ArrayAccessSignature.hx

+ 8 - 4
src/typing/typerDisplay.ml

@@ -243,10 +243,14 @@ let rec handle_signature_display ctx e_ast with_type =
 				(match a.a_impl with Some c -> ignore(c.cl_build()) | _ -> ());
 				let sigs = ExtList.List.filter_map (fun cf -> match follow cf.cf_type with
 					| TFun(_ :: args,r) ->
-						let map = apply_params a.a_params tl in
-						let tl = List.map (fun (n,o,t) -> n,o,map t) args in
-						let r = map r in
-						Some (convert_function_signature ctx PMap.empty (tl,r),cf.cf_doc)
+						if ExtType.is_void (follow r) && (match with_type with NoValue -> false | _ -> true) then
+							None
+						else begin
+							let map = apply_params a.a_params tl in
+							let tl = List.map (fun (n,o,t) -> n,o,map t) args in
+							let r = map r in
+							Some (convert_function_signature ctx PMap.empty (tl,r),cf.cf_doc)
+						end
 					| _ ->
 						None
 				) a.a_array in

+ 23 - 2
tests/display/src/cases/ArrayAccessSignature.hx

@@ -78,7 +78,7 @@ class ArrayAccessSignature extends DisplayTestCase {
 	**/
 	function testMap1() {
 		// because screw consistency
-		sigEq(0, [["key:Int"], ["k:Int"]], signature(pos(1)));
+		sigEq(0, [["key:Int"], ["k:Int", "v:Int"]], signature(pos(1)));
 	}
 
 	/**
@@ -91,6 +91,27 @@ class ArrayAccessSignature extends DisplayTestCase {
 	}
 	**/
 	function testInCall1() {
-		sigEq(0, [["key:Int"], ["k:Int"]], signature(pos(1)));
+		sigEq(0, [["key:Int"], ["k:Int", "v:Int"]], signature(pos(1)));
+	}
+
+	/**
+	abstract MyArray<T>(Array<T>) {
+		public function new() this = [];
+
+		@:op([])
+		function arrayRead(k:Int):T return cast this[k];
+
+		@:op([])
+		function arrayReadWrite(k:Int, v:T) this[k] = v;
+	}
+	class Some {
+		function main() {
+			var m = new MyArray();
+			var k = m[{-1-}
+		}
+	}
+	**/
+	function testVoidReturn() {
+		sigEq(0, [["k:Int"]], signature(pos(1)));
 	}
 }