Browse Source

transform `return (e:Void)` to `e; return` (closes #3279)

Simon Krajewski 11 years ago
parent
commit
31bc42caab
3 changed files with 21 additions and 8 deletions
  1. 2 0
      filters.ml
  2. 19 0
      tests/unit/issues/Issue3280.hx
  3. 0 8
      typer.ml

+ 2 - 0
filters.ml

@@ -220,6 +220,8 @@ let promote_complex_rhs ctx e =
 						r := (mk (TVar (v,Some (find e))) ctx.basic.tvoid e.epos) :: !r
 						r := (mk (TVar (v,Some (find e))) ctx.basic.tvoid e.epos) :: !r
 					| None -> r := (mk (TVar (v,None)) ctx.basic.tvoid e.epos) :: !r
 					| None -> r := (mk (TVar (v,None)) ctx.basic.tvoid e.epos) :: !r
 				end
 				end
+			| TReturn (Some e1) when (match follow e1.etype with TAbstract({a_path=[],"Void"},_) -> true | _ -> false) ->
+				r := ({e with eexpr = TReturn None}) :: e1 :: !r
 			| _ -> r := (find e) :: !r
 			| _ -> r := (find e) :: !r
 		) el;
 		) el;
 		List.rev !r
 		List.rev !r

+ 19 - 0
tests/unit/issues/Issue3280.hx

@@ -0,0 +1,19 @@
+package unit.issues;
+
+class Issue3280 extends Test {
+
+    static function recurse( i : Int, param : String ) {
+        if( i > 0 ) {
+			param += iter(i, recurse.bind(_,param));
+		}
+		return param;
+    }
+
+    static function iter( v : Int, f) {
+        return f(v-1);
+    }
+
+	function test() {
+		eq("aaaa", recurse(3, "a"));
+	}
+}

+ 0 - 8
typer.ml

@@ -1572,14 +1572,6 @@ let type_bind ctx (e : texpr) params p =
 		| TAbstract ({a_path = [],"Void"},_) ->
 		| TAbstract ({a_path = [],"Void"},_) ->
 			call
 			call
 		| TMono _ ->
 		| 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;
 		| _ ->
 		| _ ->
 			mk (TReturn (Some call)) t_dynamic p;
 			mk (TReturn (Some call)) t_dynamic p;