Explorar o código

check abstract casts when typing if (fixed issue #1845)

Simon Krajewski %!s(int64=12) %!d(string=hai) anos
pai
achega
bc5019d057
Modificáronse 1 ficheiros con 7 adicións e 5 borrados
  1. 7 5
      typer.ml

+ 7 - 5
typer.ml

@@ -2683,10 +2683,10 @@ and type_expr ctx (e,p) (with_type:with_type) =
 			mk (TIf (e,e1,None)) ctx.t.tvoid p
 			mk (TIf (e,e1,None)) ctx.t.tvoid p
 		| Some e2 ->
 		| Some e2 ->
 			let e2 = type_expr ctx e2 with_type in
 			let e2 = type_expr ctx e2 with_type in
-			let t = match with_type with
-				| NoValue -> ctx.t.tvoid
-				| Value -> unify_min ctx [e1; e2]
-				| WithType t | WithTypeResume t when (match follow t with TMono _ -> true | _ -> false) -> unify_min ctx [e1; e2]
+			let e1,e2,t = match with_type with
+				| NoValue -> e1,e2,ctx.t.tvoid
+				| Value -> e1,e2,unify_min ctx [e1; e2]
+				| WithType t | WithTypeResume t when (match follow t with TMono _ -> true | _ -> false) -> e1,e2,unify_min ctx [e1; e2]
 				| WithType t | WithTypeResume t ->
 				| WithType t | WithTypeResume t ->
 					begin try
 					begin try
 						unify_raise ctx e1.etype t e1.epos;
 						unify_raise ctx e1.etype t e1.epos;
@@ -2695,7 +2695,9 @@ and type_expr ctx (e,p) (with_type:with_type) =
 						| WithTypeResume _ -> raise (WithTypeError (l,p))
 						| WithTypeResume _ -> raise (WithTypeError (l,p))
 						| _ -> display_error ctx (error_msg (Unify l)) p
 						| _ -> display_error ctx (error_msg (Unify l)) p
 					end;
 					end;
-					t
+					let e1 = Codegen.Abstract.check_cast ctx t e1 e1.epos in
+					let e2 = Codegen.Abstract.check_cast ctx t e2 e2.epos in
+					e1,e2,t
 			in
 			in
 			mk (TIf (e,e1,Some e2)) t p)
 			mk (TIf (e,e1,Some e2)) t p)
 	| EWhile (cond,e,NormalWhile) ->
 	| EWhile (cond,e,NormalWhile) ->