Browse Source

do not inline constructors if the variable type differs (see #3967)

Simon Krajewski 10 years ago
parent
commit
d7d3c366ca
2 changed files with 7 additions and 7 deletions
  1. 3 3
      optimizer.ml
  2. 4 4
      tests/unit/src/unit/issues/Issue3967.hx

+ 3 - 3
optimizer.ml

@@ -1310,7 +1310,7 @@ let inline_constructors ctx e =
 			begin match eo with
 				| Some n ->
 					begin match get_inline_ctor_info n with
-					| IKCtor (f,cst,c,tl,pl,el_init) ->
+					| IKCtor (f,cst,c,tl,pl,el_init) when type_iseq v.v_type n.etype ->
 						(* inline the constructor *)
 						(match (try type_inline ctx cst f (mk (TLocal v) (TInst (c,tl)) n.epos) pl ctx.t.tvoid None n.epos true with Error (Custom _,_) -> None) with
 						| None -> ()
@@ -1346,10 +1346,10 @@ let inline_constructors ctx e =
 					| IKStructure fl ->
 						vars := PMap.add v.v_id (v,[],List.map (fun (s,e) -> s,e,e.etype) fl, false, n.epos) !vars;
 						v.v_id <- -v.v_id;
-					| IKNone ->
+					| _ ->
 						()
 					end
-				| None -> ()
+				| _ -> ()
 			end
 		| TField(e1, (FInstance(_, _, {cf_kind = Var _; cf_name = s}) | FAnon({cf_kind = Var _; cf_name = s}))) ->
 			(match skip_to_var e1 with None -> find_locals e1 | Some _ -> ())

+ 4 - 4
tests/unit/src/unit/issues/Issue3967.hx

@@ -18,8 +18,8 @@ class Issue3967 extends Test {
 		f(a == b);
 	}
 
-	//function testNicolas() {
-		//var x:{ var test(default,never) : Void -> String; } = new A("foo");
-		//eq("foo", x.test());
-	//}
+	function testNicolas() {
+		var x:{ var test(default,never) : Void -> String; } = new A("foo");
+		eq("foo", x.test());
+	}
 }