Permalink
Browse files

use unify_min on return

git-svn-id: http://haxe.googlecode.com/svn/trunk@4592 f16182fa-f095-11de-8f43-4547254af6c6
  • Loading branch information...
simon.krajewski@simn.de
simon.krajewski@simn.de committed May 10, 2012
1 parent 62e354a commit e61437ae0b0a8b6194bf8c49160a11680183ed15
Showing with 10 additions and 2 deletions.
  1. +1 −1 typecore.ml
  2. +5 −0 typeload.ml
  3. +4 −1 typer.ml
View
@@ -300,5 +300,5 @@ let unify_min_raise ctx el =
let unify_min ctx el =
try unify_min_raise ctx el
with Error (Unify l,p) ->
- display_error ctx (error_msg (Unify l)) p;
+ if not ctx.untyped then display_error ctx (error_msg (Unify l)) p;
(List.hd el).etype
View
@@ -571,12 +571,16 @@ let type_function ctx args ret fmode f p =
add_local ctx n t, c
) args in
let old_ret = ctx.ret in
+ let old_ret_exprs = ctx.ret_exprs in
let old_fun = ctx.curfun in
let old_opened = ctx.opened in
ctx.curfun <- fmode;
ctx.ret <- ret;
+ ctx.ret_exprs <- [];
ctx.opened <- [];
let e = type_expr ctx (match f.f_expr with None -> error "Function body required" p | Some e -> e) false in
+ let t = unify_min ctx ctx.ret_exprs in
+ unify ctx t ctx.ret e.epos;
let rec loop e =
match e.eexpr with
| TReturn (Some _) -> raise Exit
@@ -617,6 +621,7 @@ let type_function ctx args ret fmode f p =
in
List.iter (fun r -> r := Closed) ctx.opened;
ctx.ret <- old_ret;
+ ctx.ret_exprs <- old_ret_exprs;
ctx.curfun <- old_fun;
ctx.opened <- old_opened;
e , fargs
View
@@ -1544,7 +1544,10 @@ and type_expr ctx ?(need_val=true) (e,p) =
None , v
| Some e ->
let e = type_expr ctx e in
- unify ctx e.etype ctx.ret e.epos;
+ if ctx.untyped || ctx.ret == t_dynamic then
+ unify ctx e.etype ctx.ret e.epos
+ else
+ ctx.ret_exprs <- e :: ctx.ret_exprs;
Some e , e.etype
) in
mk (TReturn e) t_dynamic p

0 comments on commit e61437a

Please sign in to comment.