瀏覽代碼

error if a bind function return type turns out to be Void (closes #3026)

Simon Krajewski 11 年之前
父節點
當前提交
054b043fce
共有 2 個文件被更改,包括 16 次插入4 次删除
  1. 2 2
      tests/unit/Test.hx
  2. 14 2
      typer.ml

+ 2 - 2
tests/unit/Test.hx

@@ -103,7 +103,7 @@ class Test #if swf_mark implements mt.Protect #end {
 		reportInfos = m;
 	}
 
-	function async<Args,T>( f : Args -> (T -> Void) -> Void, args : Args, v : T, ?pos : haxe.PosInfos ) {
+	function async<Args,T>( f : Args -> (T -> Void) -> Void, args : Args, v : T, ?pos : haxe.PosInfos ) : Void {
 		if( asyncWaits.length >= AMAX ) {
 			asyncCache.push(async.bind(f,args,v,pos));
 			return;
@@ -124,7 +124,7 @@ class Test #if swf_mark implements mt.Protect #end {
 		});
 	}
 
-	function asyncExc<Args>( seterror : (Dynamic -> Void) -> Void, f : Args -> (Dynamic -> Void) -> Void, args : Args, ?pos : haxe.PosInfos ) {
+	function asyncExc<Args>( seterror : (Dynamic -> Void) -> Void, f : Args -> (Dynamic -> Void) -> Void, args : Args, ?pos : haxe.PosInfos ) : Void {
 		if( asyncWaits.length >= AMAX ) {
 		asyncCache.push(asyncExc.bind(seterror,f,args,pos));
 			return;

+ 14 - 2
typer.ml

@@ -1550,8 +1550,20 @@ let type_bind ctx (e : texpr) params p =
 	let t_inner = TFun(inner_fun_args missing_args, ret) in
 	let call = make_call ctx (vexpr loc) ordered_args ret p in
 	let e_ret = match follow ret with
-		| TAbstract ({a_path = [],"Void"},_) -> call
-		| _ -> mk (TReturn (Some call)) t_dynamic p;
+		| TAbstract ({a_path = [],"Void"},_) ->
+			call
+		| TMono _ ->
+			delay ctx PFinal (fun () ->
+				match follow ret with
+				| TAbstract ({a_path = [],"Void"},_) ->
+					display_error ctx "Could not bind this function because its Void return type was inferred too late" p;
+					error "Consider an explicit type hint" p
+				| _ ->
+					()
+			);
+			mk (TReturn (Some call)) t_dynamic p;
+		| _ ->
+			mk (TReturn (Some call)) t_dynamic p;
 	in
 	let func = mk (TFunction {
 		tf_args = List.map (fun (v,o) -> v, if o then Some TNull else None) missing_args;