浏览代码

[flash] cast interface var access

closes #7727
Simon Krajewski 6 年之前
父节点
当前提交
cd1f301014
共有 2 个文件被更改,包括 32 次插入3 次删除
  1. 6 3
      src/generators/genswf9.ml
  2. 26 0
      tests/unit/src/unit/issues/Issue7727.hx

+ 6 - 3
src/generators/genswf9.ml

@@ -902,14 +902,17 @@ 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
+			let requires_cast = match fa with
+				| FInstance({cl_interface=true},_,{cf_kind = Var _}) ->
+					(* we have to cast var access on interfaces *)
+					true
 				| FInstance(_,_,cf) ->
+					(* if the return type is one of the type-parameters, then we need to cast it *)
 					(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 is_type_parameter_field then
+			if requires_cast then
 				VCast (id, classify ctx e.etype)
 			else if Codegen.is_volatile e.etype then
 				VVolatile (id,None)

+ 26 - 0
tests/unit/src/unit/issues/Issue7727.hx

@@ -0,0 +1,26 @@
+package unit.issues;
+
+private enum E {
+	A;
+	B;
+}
+
+private interface I {
+	var e:E;
+}
+
+class Issue7727 extends unit.Test implements I {
+	public var e:E;
+
+	function test() {
+		e = A;
+		eq(1, run(this));
+	}
+
+	static function run(i:I) {
+		switch(i.e) {
+			case A: return 1;
+			case B: return 2;
+		}
+	}
+}