Forráskód Böngészése

[flash] utilize FInstance information to determine if we need to cast type parameter fields (closes #523) (it belongs in a museum)

Simon Krajewski 11 éve
szülő
commit
6c6fc3859d
2 módosított fájl, 47 hozzáadás és 3 törlés
  1. 9 3
      genswf9.ml
  2. 38 0
      tests/unit/issues/Issue523.hx

+ 9 - 3
genswf9.ml

@@ -884,8 +884,8 @@ let rec gen_access ctx e (forset : 'a) : 'a access =
 		write ctx (HGetProp (ident "params"));
 		write ctx (HSmallInt i);
 		VArray
-	| TField (e1,f) ->
-		let f = field_name f in
+	| TField (e1,fa) ->
+		let f = field_name fa in
 		let id, k, closure = property ctx f e1.etype in
 		if closure && not ctx.for_call then error "In Flash9, this method cannot be accessed this way : please define a local function" e1.epos;
 		(match e1.eexpr with
@@ -899,8 +899,14 @@ let rec gen_access ctx e (forset : 'a) : 'a access =
 		| _ , TFun _ when not ctx.for_call -> VCast(id,classify ctx e.etype)
 		| TEnum _, _ -> VId id
 		| TInst (_,tl), et ->
+			let is_type_parameter_field = match fa with
+				| FInstance(_,_,cf) ->
+					(match follow cf.cf_type with TInst({cl_kind = KTypeParameter _},_) -> true | _ -> false)
+				| _ ->
+					List.exists (fun t -> follow t == et) tl
+			in
 			(* if the return type is one of the type-parameters, then we need to cast it *)
-			if List.exists (fun t -> follow t == et) tl then
+			if is_type_parameter_field then
 				VCast (id, classify ctx et)
 			else if Codegen.is_volatile e.etype then
 				VVolatile (id,None)

+ 38 - 0
tests/unit/issues/Issue523.hx

@@ -0,0 +1,38 @@
+package unit.issues;
+
+private class A extends Arr<B> {
+	public function new() {
+		super(new B(this));
+	}
+}
+
+private class B {
+	var arr:Arr<B>;
+
+	public function new(arr:Arr<B>) {
+		this.arr = arr;
+	}
+
+	public inline function getColor(strength:Int) {
+		switch (arr.index) {
+			case _: return strength;
+		}
+	}
+}
+
+private class Arr<T> {
+	public var index:Int;
+	public var v:T;
+
+	public function new(v) {
+		this.index = 0;
+		this.v = v;
+	}
+}
+
+class Issue523 extends Test {
+	function test() {
+		var a = new A();
+		eq(142, a.v.getColor(142));
+	}
+}