Browse Source

add `maybe_cast` but don't use it because it causes overload ambiguities on C#

Simon Krajewski 10 years ago
parent
commit
aa2c12935a
2 changed files with 10 additions and 1 deletions
  1. 7 0
      codegen.ml
  2. 3 1
      typer.ml

+ 7 - 0
codegen.ml

@@ -47,6 +47,13 @@ let binop op a b t p =
 let index com e index t p =
 	mk (TArray (e,mk (TConst (TInt (Int32.of_int index))) com.basic.tint p)) t p
 
+let maybe_cast e t =
+	try
+		type_eq EqDoNotFollowNull e.etype t;
+		e
+	with
+		Unify_error _ -> mk (TCast(e,None)) t e.epos
+
 let type_constant com c p =
 	let t = com.basic in
 	match c with

+ 3 - 1
typer.ml

@@ -2198,7 +2198,9 @@ and type_binop2 ctx op (e1 : texpr) (e2 : Ast.expr) is_assign_op wt p =
 								error (Printf.sprintf "The result of this operation (%s) is not compatible with declared return type %s" (st t_expected) (st tret)) p
 					end;
 				end;
-				mk_cast (Codegen.binop op e1 e2 tret p) tret p
+				let e = Codegen.binop op e1 e2 tret p in
+				mk_cast e tret p
+				(* Codegen.maybe_cast e tret *)
 			end else begin
 				let e = make_static_call ctx c cf map [e1;e2] tret p in
 				e