Browse Source

fixed bugs with properties in interface (fixed issue #742, fixed issue #752)

Nicolas Cannasse 13 years ago
parent
commit
4885a6b567
3 changed files with 34 additions and 14 deletions
  1. 7 7
      genphp.ml
  2. 14 6
      genswf9.ml
  3. 13 1
      tests/unit/TestReflect.hx

+ 7 - 7
genphp.ml

@@ -2005,13 +2005,13 @@ let generate_class ctx c =
 			list
 	in
 	
-	(match fields c with
-	| [] ->
-		()
-	| props ->
-		newline ctx;
-		print ctx "static $__properties__ = array(%s)" (gen_props props);
-	);
+	if not c.cl_interface then (match fields c with
+		| [] ->
+			()
+		| props ->
+			newline ctx;
+			print ctx "static $__properties__ = array(%s)" (gen_props props);
+		);
 		
 		
 	cl();

+ 14 - 6
genswf9.ml

@@ -1998,9 +1998,13 @@ let generate_class ctx c =
 			let acc = (match v.v_read with
 				| AccCall n when n <> "get_" ^ f.cf_name ->
 					(* generate get_xxx method *)
-					let fk = begin_fun ctx [] f.cf_type [ethis] false p in
-					gen_expr ctx false (mk (TReturn (Some (mk (TCall (mk (TField (ethis,n)) t_dynamic p,[])) f.cf_type p))) t_dynamic p);
-					let m = fk() in
+					let m = if c.cl_interface then
+						end_fun ctx [] None f.cf_type
+					else
+						let fk = begin_fun ctx [] f.cf_type [ethis] false p in
+						gen_expr ctx false (mk (TReturn (Some (mk (TCall (mk (TField (ethis,n)) t_dynamic p,[])) f.cf_type p))) t_dynamic p);
+						fk()
+					in
 					{
 						hlf_name = ident ("get_" ^ f.cf_name);
 						hlf_slot = alloc_slot();
@@ -2019,9 +2023,13 @@ let generate_class ctx c =
 				| AccCall n when n <> "set_" ^ f.cf_name ->
 					(* generatee set_xxx method *)
 					let v = alloc_var "tmp" f.cf_type in
-					let fk = begin_fun ctx [v,None] f.cf_type [ethis] false p in
-					gen_expr ctx false (mk (TReturn (Some (mk (TCall (mk (TField (ethis,n)) t_dynamic p,[mk (TLocal v) v.v_type p])) f.cf_type p))) t_dynamic p);
-					let m = fk() in
+					let m = if c.cl_interface then
+						end_fun ctx [v,None] None f.cf_type
+					else
+						let fk = begin_fun ctx [v,None] f.cf_type [ethis] false p in
+						gen_expr ctx false (mk (TReturn (Some (mk (TCall (mk (TField (ethis,n)) t_dynamic p,[mk (TLocal v) v.v_type p])) f.cf_type p))) t_dynamic p);
+						fk()
+					in
 					{
 						hlf_name = ident ("set_" ^ f.cf_name);
 						hlf_slot = alloc_slot();

+ 13 - 1
tests/unit/TestReflect.hx

@@ -1,7 +1,11 @@
 package unit;
 import Type;
 
-class ClassWithProp {
+interface InterfWithProp {
+	public var x(getX, setX) : Int;
+}
+
+class ClassWithProp implements InterfWithProp {
 	public var x(getX, setX) : Int;
 	var _x : Int;
 
@@ -244,6 +248,14 @@ class TestReflect extends Test {
 		var c = new ClassWithProp();
 		eq( c.x, 5);
 
+		eq( Reflect.getProperty(c, "x"), 5);
+		Reflect.setProperty(c, "x", 10);
+		eq( c.x, 10);
+		eq( Reflect.getProperty(c, "x"), 10);
+		
+		var c : InterfWithProp = new ClassWithProp();
+		eq( c.x, 5);
+
 		eq( Reflect.getProperty(c, "x"), 5);
 		Reflect.setProperty(c, "x", 10);
 		eq( c.x, 10);