Explorar o código

[display] check whether the type we want to get signature for is actually callable (closes #6068)

Dan Korostelev %!s(int64=8) %!d(string=hai) anos
pai
achega
4eb695e918
Modificáronse 2 ficheiros con 30 adicións e 1 borrados
  1. 2 1
      src/typing/typer.ml
  2. 28 0
      tests/display/src/cases/Issue6068.hx

+ 2 - 1
src/typing/typer.ml

@@ -3717,7 +3717,8 @@ and handle_signature_display ctx e_ast with_type =
 	in
 	in
 	let rec follow_with_callable (t,doc) = match follow t with
 	let rec follow_with_callable (t,doc) = match follow t with
 		| TAbstract(a,tl) when Meta.has Meta.Callable a.a_meta -> follow_with_callable (Abstract.get_underlying_type a tl,doc)
 		| TAbstract(a,tl) when Meta.has Meta.Callable a.a_meta -> follow_with_callable (Abstract.get_underlying_type a tl,doc)
-		| t -> (t,doc)
+		| TFun(_,_) as t -> (t,doc)
+		| _ -> error ("Not a callable type: " ^ (s_type (print_context()) t)) p
 	in
 	in
 	let tl = List.map follow_with_callable tl in
 	let tl = List.map follow_with_callable tl in
 	let rec loop i p1 el = match el with
 	let rec loop i p1 el = match el with

+ 28 - 0
tests/display/src/cases/Issue6068.hx

@@ -0,0 +1,28 @@
+package cases;
+
+class Issue6068 extends DisplayTestCase {
+	/**
+	class Main {
+		static function main() {
+			var a:{i:Int};
+			a({-1-});
+
+			Main({-2-});
+		}
+	}
+	**/
+	function test() {
+		check(function() signature(pos(1)));
+		check(function() signature(pos(2)));
+	}
+
+	function check(fn) {
+		var result = try {
+				fn();
+				false;
+			} catch (e:DisplayTestContext.HaxeInvocationException) {
+				e.message.indexOf("Not a callable type") != -1;
+			}
+		assert(result);
+	}
+}