소스 검색

do not generate multi-type abstract to-casts (closes #2917)

Simon Krajewski 11 년 전
부모
커밋
b361286c5f
2개의 변경된 파일22개의 추가작업 그리고 7개의 파일을 삭제
  1. 12 7
      codegen.ml
  2. 10 0
      tests/unit/issues/Issue2917.hx

+ 12 - 7
codegen.ml

@@ -690,15 +690,20 @@ module Abstract = struct
 		in
 		let find a tl f =
 			let tcf,cfo = f() in
+			let mk_cast () =
+				let tcf = apply_params a.a_types tl tcf in
+				if type_iseq tcf tleft then
+					eright
+				else
+					(* TODO: causes Java overload issues *)
+					(* let eright = mk (TCast(eright,None)) tleft p in *)
+					do_check_cast ctx tcf eright p
+			in
 			match cfo,a.a_impl with
 				| None,_ ->
-					let tcf = apply_params a.a_types tl tcf in
-					if type_iseq tcf tleft then
-						eright
-					else
-						(* TODO: causes Java overload issues *)
-						(* let eright = mk (TCast(eright,None)) tleft p in *)
-						do_check_cast ctx tcf eright p
+					mk_cast();
+				| Some cf,_ when Meta.has Meta.MultiType a.a_meta ->
+					mk_cast();
 				| Some cf,Some c ->
 					recurse cf (fun () -> make_static_call ctx c cf a tl [eright] tleft p)
 				| _ ->

+ 10 - 0
tests/unit/issues/Issue2917.hx

@@ -0,0 +1,10 @@
+package unit.issues;
+
+class Issue2917 extends Test {
+	function test() {
+		var m = new Map<String, Int>();
+		eq(0, Lambda.count(m));
+		m.set("foo", 12);
+		eq(1, Lambda.count(m));
+	}
+}