Prechádzať zdrojové kódy

[typer] don't run analyzer early on member init expressions

closes #10335
Aleksandr Kuzmenko 3 rokov pred
rodič
commit
4d7109a815

+ 1 - 0
extra/CHANGES.txt

@@ -15,6 +15,7 @@
 	all : fixed hanging of MainLoop.add on threaded targets (#10308, #10329)
 	all : fixed compiler crash when resolving overloads with not enough arguments (#10434)
 	analyzer : fixed analyzer on overloads (#10405)
+	analyzer : fixed issues with fields initialization expressions (#10405)
 	display : improved code completion in anonymous objects declarations (#10414)
 	js : fixed IntMap for keys greater than 2^31 (#10316)
 	js : workaround to fix sourcemaps on Firefox in Windows (#10217)

+ 0 - 5
src/typing/typeloadFields.ml

@@ -853,11 +853,6 @@ module TypeBinding = struct
 					let e = if ctx.com.display.dms_display && ctx.com.display.dms_error_policy <> EPCollect then
 						e
 					else begin
-						let e = Optimizer.reduce_loop ctx (maybe_run_analyzer e) in
-						let e = (match Optimizer.make_constant_expression ctx e with
-							| Some e -> e
-							| None -> e
-						) in
 						let rec check_this e = match e.eexpr with
 							| TConst TThis ->
 								display_error ctx "Cannot access this or other member field in variable initialization" e.epos;

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

@@ -0,0 +1,22 @@
+package unit.issues;
+
+private class NotMain {
+	public final prop = {
+		var testvalue = 1;
+		{
+			get: () -> testvalue,
+			set: v -> testvalue = v,
+		}
+	}
+
+	public function new() {}
+}
+
+class Issue10335 extends unit.Test {
+	function test() {
+		final inst = new NotMain();
+		eq(1, inst.prop.get());
+		inst.prop.set(2);
+		eq(2, inst.prop.get());
+	}
+}