Ver código fonte

[dce] keep physical fields, if their accessors are kept (fixes #7671)

Aleksandr Kuzmenko 6 anos atrás
pai
commit
70286072fc
2 arquivos alterados com 62 adições e 0 exclusões
  1. 13 0
      src/optimization/dce.ml
  2. 49 0
      tests/unit/src/unit/issues/Issue7671.hx

+ 13 - 0
src/optimization/dce.ml

@@ -113,6 +113,19 @@ let rec keep_field dce cf c is_static =
 			| Some ({ cl_constructor = Some ctor } as csup, _) -> keep_field dce ctor csup false
 			| _ -> false
 	)
+	|| begin
+		let check_accessor prefix =
+			try
+				let fields = if is_static then c.cl_statics else c.cl_fields in
+				let accessor = PMap.find (prefix ^ cf.cf_name) fields in
+				keep_field dce accessor c is_static
+			with Not_found -> false
+		in
+		match cf.cf_kind with
+		| Var { v_read = AccCall } -> check_accessor "get_"
+		| Var { v_write = AccCall } -> check_accessor "set_"
+		| _ -> false
+	end
 
 (* marking *)
 

+ 49 - 0
tests/unit/src/unit/issues/Issue7671.hx

@@ -0,0 +1,49 @@
+package unit.issues;
+
+class Issue7671 extends unit.Test {
+	function test() {
+		var d = new Dummy();
+
+		eq("getter", d.getterInstance);
+		eq("getter", Reflect.getProperty(d, "getterInstance"));
+
+		eq("getter", Dummy.getterStatic);
+		eq("getter", Reflect.getProperty(Dummy, "getterStatic"));
+
+		d.setterInstance = "hello";
+		eq("hello", d.instanceValue);
+		Reflect.setProperty(d, "setterInstance", "world");
+		eq("world", d.instanceValue);
+
+		Dummy.setterStatic = "hello";
+		eq("hello", Dummy.staticValue);
+		Reflect.setProperty(Dummy, "setterStatic", "world");
+		eq("world", Dummy.staticValue);
+	}
+}
+
+private class Dummy {
+	static public var getterStatic (get,null):String;
+	static function get_getterStatic() {
+		return "getter";
+	}
+
+	public var getterInstance (get,null):String;
+	function get_getterInstance() {
+		return "getter";
+	}
+
+	static public var setterStatic (null,set):String;
+	static public var staticValue:String;
+	static function set_setterStatic(v:String):String {
+		return staticValue = v;
+	}
+
+	public var setterInstance (null,set):String;
+	public var instanceValue:String;
+	function set_setterInstance(v:String) {
+		return instanceValue = v;
+	}
+
+	public function new(){}
+}