فهرست منبع

Fix accessor class lookup for write too (#12272)

Yuxiao Mao 1 ماه پیش
والد
کامیت
b4dcbe4128
3فایلهای تغییر یافته به همراه14 افزوده شده و 3 حذف شده
  1. 7 1
      src/typing/operators.ml
  2. 3 1
      tests/unit/src/unit/issues/Issue12259.hx
  3. 4 1
      tests/unit/src/unit/issues/misc/issue12259/Entity.hx

+ 7 - 1
src/typing/operators.ml

@@ -599,7 +599,13 @@ let type_assign ctx e1 e2 with_type p =
 			assign_to e1
 		| AKAccessor fa ->
 			let c,stat = match fa.fa_host with
-				| FHInstance(c,tl) -> Some c,false
+				| FHInstance(c,tl) ->
+					(* c refers to the host of the field, let's find the class we're actually accessing on *)
+					let c = match follow fa.fa_on.etype with
+						| TInst(c,_) -> c
+						| _ -> c
+					in
+					Some c,false
 				| FHStatic c -> Some c,true
 				| FHAbstract(a,tl,c) -> Some c,true
 				| _ -> None,false

+ 3 - 1
tests/unit/src/unit/issues/Issue12259.hx

@@ -5,6 +5,8 @@ import unit.issues.misc.issue12259.Element;
 @:access(unit.issues.misc.issue12259.Element)
 class Issue12259 extends unit.Test {
 	public function test() {
-		eq(true, new Element().foo);
+		var elt = new Element();
+		eq(true, elt.foo);
+		eq(true, elt.foo = false);
 	}
 }

+ 4 - 1
tests/unit/src/unit/issues/misc/issue12259/Entity.hx

@@ -3,8 +3,11 @@ package unit.issues.misc.issue12259;
 class Entity {
 	function new() {}
 
-	var foo(get, never):Bool;
+	var foo(get, set):Bool;
 
 	function get_foo():Bool
 		return true;
+
+	function set_foo(b : Bool):Bool
+		return true;
 }