فهرست منبع

run `rename_local_vars` in `add_field_inits` (closes #4886)

Simon Krajewski 9 سال پیش
والد
کامیت
f8494c889d
2فایلهای تغییر یافته به همراه26 افزوده شده و 1 حذف شده
  1. 4 1
      filters.ml
  2. 22 0
      tests/unit/src/unit/issues/Issue4886.hx

+ 4 - 1
filters.ml

@@ -872,7 +872,10 @@ let add_field_inits ctx t =
 			Analyzer.Run.run_on_field ctx config c cf;
 			(match cf.cf_expr with
 			| Some e ->
-				cf.cf_expr <- Some (Optimizer.sanitize ctx.com e)
+				(* This seems a bit expensive, but hopefully constructor expressions aren't that massive. *)
+				let e = rename_local_vars ctx e in
+				let e = Optimizer.sanitize ctx.com e in
+				cf.cf_expr <- Some e
 			| _ ->
 				());
 			c.cl_constructor <- Some cf

+ 22 - 0
tests/unit/src/unit/issues/Issue4886.hx

@@ -0,0 +1,22 @@
+package unit.issues;
+
+private class C {
+	inline function get() {
+		var intStruct = { i: 0 };
+		return intStruct;
+	}
+
+	var a = [get(), get(), get()];
+
+	public var b:Bool;
+	public function new() {
+		b = a[0] == a[1];
+	}
+}
+
+class Issue4886 extends Test {
+	function test() {
+		var c = new C();
+		f(c.b);
+	}
+}