Bläddra i källkod

[as3] detect calls to methods that had their return type fixed and add a cast (closes #4222)

Simon Krajewski 10 år sedan
förälder
incheckning
5c675abf6b
2 ändrade filer med 44 tillägg och 0 borttagningar
  1. 22 0
      genas3.ml
  2. 22 0
      tests/unit/src/unit/issues/Issue4222.hx

+ 22 - 0
genas3.ml

@@ -62,6 +62,20 @@ let is_special_compare e1 e2 =
 	| TInst ({ cl_path = ["flash"],"NativeXml" } as c,_) , _ | _ , TInst ({ cl_path = ["flash"],"NativeXml" } as c,_) -> Some c
 	| _ -> None
 
+let is_fixed_override cf t =
+	let is_type_parameter c = match c.cl_kind with
+		| KTypeParameter _ -> true
+		| _ -> false
+	in
+	match follow cf.cf_type,follow t with
+	| TFun(_,r1),TFun(_,r2) ->
+		begin match follow r1,follow r2 with
+		| TInst(c1,_),TInst(c2,_) when c1 != c2 && not (is_type_parameter c1) && not (is_type_parameter c2) -> true
+		| _ -> false
+		end
+	| _ ->
+		false
+
 let protect name =
 	match name with
 	| "Error" | "Namespace" -> "_" ^ name
@@ -521,6 +535,14 @@ let rec gen_call ctx e el r =
 		spr ctx "(";
 		concat ctx "," (gen_value ctx) el;
 		spr ctx ")"
+	| TField (e1,FInstance(_,_,cf)),el when is_fixed_override cf e.etype ->
+		let s = type_str ctx r e.epos in
+		spr ctx "((";
+		gen_value ctx e;
+		spr ctx "(";
+		concat ctx "," (gen_value ctx) el;
+		spr ctx ")";
+		print ctx ") as %s)" s
 	| _ ->
 		gen_value ctx e;
 		spr ctx "(";

+ 22 - 0
tests/unit/src/unit/issues/Issue4222.hx

@@ -0,0 +1,22 @@
+package unit.issues;
+
+private class Base {
+	public function new() { }
+	public function covariant():Base {
+		return this;
+	}
+}
+
+private class Child extends Base {
+	public override function covariant():Child {
+		return this;
+	}
+}
+
+
+class Issue4222 extends Test {
+	function test() {
+		var c = new Child();
+		var v = c.covariant();
+	}
+}