소스 검색

use is_extern_field to determine which fields to initialize (closes #https://github.com/frabbit/hx2python/issues/26)

Simon Krajewski 11 년 전
부모
커밋
898644ce39
2개의 변경된 파일21개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      genpy.ml
  2. 20 0
      tests/unit/TestPython.hx

+ 1 - 1
genpy.ml

@@ -1432,7 +1432,7 @@ module Generator = struct
 
 	let get_members_with_init_expr c =
 		List.filter (fun cf -> match cf.cf_kind with
-			| Var({v_read = AccResolve | AccCall _}) -> false
+			| Var _ when is_extern_field cf -> false
 			| Var _ when cf.cf_expr = None -> true
 			| _ -> false
 		) c.cl_ordered_fields

+ 20 - 0
tests/unit/TestPython.hx

@@ -159,4 +159,24 @@ class TestPython extends Test {
 			e = 1;
 		}
 	}
+
+	var _s:String;
+
+	var s(get, null):String;
+	var s2(null, set_s2):String;
+	var s3(get, set):String;
+
+	function get_s() return s;
+	function set_s2(s) return s2 = s;
+	function get_s3() return _s;
+	function set_s3(s) return _s = s;
+
+    function testPropertyInit() {
+		s += "a";
+		s2 += "b";
+		s3 += "c";
+		eq("nulla", s);
+		eq("nullb", s2);
+		eq("nullc", s3);
+    }
 }