Kaynağa Gözat

[typer] delay interface accessor generation properly

closes #6225
closes #6672
Simon Krajewski 8 yıl önce
ebeveyn
işleme
72a65dfd66

+ 2 - 2
src/typing/typeload.ml

@@ -2675,7 +2675,7 @@ module ClassInitializer = struct
 			| get,pget ->
 				let get = if get = "get" then "get_" ^ name else get in
 				if fctx.is_display_field && Display.is_display_position pget then delay ctx PTypeField (fun () -> display_accessor get pget);
-				if not cctx.is_lib then delay ctx PTypeField (fun() -> check_method get t_get (if get <> "get" && get <> "get_" ^ name then Some ("get_" ^ name) else None));
+				if not cctx.is_lib then delay_late ctx PBuildClass (fun() -> check_method get t_get (if get <> "get" && get <> "get_" ^ name then Some ("get_" ^ name) else None));
 				AccCall
 		) in
 		let set = (match set with
@@ -2691,7 +2691,7 @@ module ClassInitializer = struct
 			| set,pset ->
 				let set = if set = "set" then "set_" ^ name else set in
 				if fctx.is_display_field && Display.is_display_position pset then delay ctx PTypeField (fun () -> display_accessor set pset);
-				if not cctx.is_lib then delay ctx PTypeField (fun() -> check_method set t_set (if set <> "set" && set <> "set_" ^ name then Some ("set_" ^ name) else None));
+				if not cctx.is_lib then delay_late ctx PBuildClass (fun() -> check_method set t_set (if set <> "set" && set <> "set_" ^ name then Some ("set_" ^ name) else None));
 				AccCall
 		) in
 		if set = AccNormal && (match get with AccCall -> true | _ -> false) then error (name ^ ": Unsupported property combination") p;

+ 30 - 0
tests/optimization/src/issues/Issue6225.hx

@@ -0,0 +1,30 @@
+package issues;
+
+import TestJs.use;
+
+class Issue6225 {
+	@:js('
+		var b = issues_Issue6225.getB();
+		issues_Issue6225.a.set_p(0 > b ? 0 : b);
+	')
+	@:analyzer(no_optimize)
+	static function test() {
+		a.p = max(0, getB());
+	}
+
+	@:js('
+		var b = issues_Issue6225.getB();
+		issues_Issue6225.a.set_p(0 > b ? 0 : b);
+	')
+	static function test2() {
+		a.p = max(0, getB());
+	}
+
+    static inline function max(a:Int, b:Int):Int return a > b ? a : b;
+    static function getB() return 1;
+    static var a:I;
+}
+
+interface I {
+    var p(get, set):Int;
+}

+ 30 - 0
tests/optimization/src/issues/Issue6672.hx

@@ -0,0 +1,30 @@
+package issues;
+
+class Issue6672 {
+	@:js('
+		var o = new issues_Issue6672();
+		null.set_prop(o);
+	')
+	@:analyzer(no_optimize)
+	static function test() {
+		(null:IFace).prop = init(new Issue6672(), function(o) {});
+	}
+
+	@:js('
+		null.set_prop(new issues_Issue6672());
+	')
+	static function test2() {
+		(null:IFace).prop = init(new Issue6672(), function(o) {});
+	}
+
+	public static inline function init(o:Issue6672, action:Issue6672->Void):Issue6672 {
+		action(o);
+		return o;
+	}
+
+	function new() {}
+}
+
+interface IFace {
+	var prop(get, set):Issue6672;
+}