Pārlūkot izejas kodu

look up correct class when calling can_access for accessors

closes #12259
closes #12271
Simon Krajewski 6 mēneši atpakaļ
vecāks
revīzija
06150d1a61

+ 7 - 1
src/typing/calls.ml

@@ -232,7 +232,13 @@ let rec acc_get ctx g =
 		end
 	| 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
 			| FHAnon -> None,false

+ 10 - 0
tests/unit/src/unit/issues/Issue12259.hx

@@ -0,0 +1,10 @@
+package unit.issues;
+
+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);
+	}
+}

+ 3 - 0
tests/unit/src/unit/issues/misc/issue12259/Element.hx

@@ -0,0 +1,3 @@
+package unit.issues.misc.issue12259;
+
+class Element extends Entity {}

+ 10 - 0
tests/unit/src/unit/issues/misc/issue12259/Entity.hx

@@ -0,0 +1,10 @@
+package unit.issues.misc.issue12259;
+
+class Entity {
+	function new() {}
+
+	var foo(get, never):Bool;
+
+	function get_foo():Bool
+		return true;
+}