2
0
Эх сурвалжийг харах

fix @:allow(pack) for inherited constructor (#6525)

Aleksandr Kuzmenko 6 жил өмнө
parent
commit
255bac073f

+ 4 - 1
src/context/typecore.ml

@@ -393,7 +393,10 @@ let rec can_access ctx ?(in_overload=false) c cf stat =
 				let allowed f = is_parent c ctx.curclass || (List.exists (has Meta.Allow c f) !cur_paths) in
 				if is_constr
 				then (match c.cl_constructor with
-					| Some cf -> if allowed cf then true else raise Not_found
+					| Some cf ->
+						if allowed cf then true
+						else if cf.cf_expr = None then false (* maybe it's an inherited auto-generated constructor *)
+						else raise Not_found
 					| _ -> false
 				)
 				else try allowed (PMap.find cf.cf_name (if stat then c.cl_statics else c.cl_fields)) with Not_found -> false

+ 3 - 1
tests/misc/projects/Issue6525/Main.hx

@@ -1,10 +1,12 @@
 import pack.BasePack;
 import pack.IPack;
 import pack.Pvt;
+import pack.sub.AccessSubPvt;
 
 class Main {
 	static function main() {
-
+		//should pass, because pack.sub.SubPvt has @:allow(pack)
+		AccessSubPvt.constructExtSubPvt();
 	}
 }
 

+ 2 - 2
tests/misc/projects/Issue6525/compile-fail.hxml.stderr

@@ -1,2 +1,2 @@
-Main.hx:14: characters 3-16 : Cannot access private field testPack
-Main.hx:15: characters 3-16 : Cannot access private field testPack
+Main.hx:16: characters 3-16 : Cannot access private field testPack
+Main.hx:17: characters 3-16 : Cannot access private field testPack

+ 7 - 0
tests/misc/projects/Issue6525/pack/sub/AccessSubPvt.hx

@@ -0,0 +1,7 @@
+package pack.sub;
+
+class AccessSubPvt {
+	static public function constructExtSubPvt():ExtSubPvt {
+		return new ExtSubPvt();
+	}
+}

+ 5 - 0
tests/misc/projects/Issue6525/pack/sub/ExtSubPvt.hx

@@ -0,0 +1,5 @@
+package pack.sub;
+
+class ExtSubPvt extends SubPvt {
+
+}

+ 6 - 0
tests/misc/projects/Issue6525/pack/sub/SubPvt.hx

@@ -0,0 +1,6 @@
+package pack.sub;
+
+@:allow(pack)
+class SubPvt {
+	function new():Void {}
+}