Quellcode durchsuchen

[typer] consume bypass_accessor only if it's actually relevant

closes #11488
Simon Krajewski vor 1 Jahr
Ursprung
Commit
4379eea3d5
2 geänderte Dateien mit 31 neuen und 4 gelöschten Zeilen
  1. 2 4
      src/typing/fields.ml
  2. 29 0
      tests/unit/src/unit/issues/Issue11488.hx

+ 2 - 4
src/typing/fields.ml

@@ -109,7 +109,7 @@ let field_access ctx mode f fh e pfield =
 	let pfull = punion e.epos pfield in
 	let is_set = match mode with MSet _ -> true | _ -> false in
 	check_no_closure_meta ctx f fh mode pfield;
-	let bypass_accessor = if ctx.bypass_accessor > 0 then (ctx.bypass_accessor <- ctx.bypass_accessor - 1; true) else false in
+	let bypass_accessor () = if ctx.bypass_accessor > 0 then (ctx.bypass_accessor <- ctx.bypass_accessor - 1; true) else false in
 	let make_access inline = FieldAccess.create e f fh (inline && ctx.allow_inline) pfull in
 	match f.cf_kind with
 	| Method m ->
@@ -208,8 +208,6 @@ let field_access ctx mode f fh e pfield =
 		| AccCall ->
 			let m = (match mode with MSet _ -> "set_" | _ -> "get_") ^ f.cf_name in
 			let bypass_accessor =
-				bypass_accessor
-				||
 				(
 					m = ctx.curfield.cf_name
 					&&
@@ -218,7 +216,7 @@ let field_access ctx mode f fh e pfield =
 					| TLocal v -> Option.map_default (fun vthis -> v == vthis) false ctx.vthis
 					| TTypeExpr (TClassDecl c) when c == ctx.curclass -> true
 					| _ -> false
-				)
+				) || bypass_accessor ()
 			in
 			if bypass_accessor then (
 				(match e.eexpr with TLocal _ when Common.defined ctx.com Define.Haxe3Compat -> warning ctx WTemp "Field set has changed here in Haxe 4: call setter explicitly to keep Haxe 3.x behaviour" pfield | _ -> ());

+ 29 - 0
tests/unit/src/unit/issues/Issue11488.hx

@@ -0,0 +1,29 @@
+package unit.issues;
+
+private class Parent {
+	public var that:Parent;
+	public var visible(default, set) = true;
+
+	public function new()
+		that = this;
+
+	public function set_visible(v:Bool) {
+		throw "set_visible was called";
+	}
+
+	public function drawRec() {}
+}
+
+private class Child extends Parent {
+	override function drawRec() {
+		@:bypassAccessor that.visible = false;
+	}
+}
+
+class Issue11488 extends Test {
+	function test() {
+		var child = new Child();
+		child.drawRec();
+		f(child.visible);
+	}
+}