Browse Source

make @:allow(some.Module) accept all the types in the Module (closes #10127)

Aleksandr Kuzmenko 4 years ago
parent
commit
13e37f4508
2 changed files with 22 additions and 5 deletions
  1. 7 5
      src/context/typecore.ml
  2. 15 0
      tests/unit/src/unit/issues/Issue10127.hx

+ 7 - 5
src/context/typecore.ml

@@ -511,7 +511,8 @@ let rec can_access ctx c cf stat =
 		in
 		loop c.cl_meta || loop f.cf_meta
 	in
-	let cur_paths = ref [] in
+	let module_path = ctx.curclass.cl_module.m_path in
+	let cur_paths = ref [fst module_path @ [snd module_path], false] in
 	let rec loop c is_current_path =
 		cur_paths := (make_path c ctx.curfield, is_current_path) :: !cur_paths;
 		begin match c.cl_super with
@@ -528,15 +529,16 @@ let rec can_access ctx c cf stat =
 			|| (
 				(* if our common ancestor declare/override the field, then we can access it *)
 				let allowed f = extends ctx.curclass c || (List.exists (has Meta.Allow c f) !cur_paths) in
-				if is_constr
-				then (match c.cl_constructor with
+				if is_constr then (
+					match c.cl_constructor with
 					| 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
+				) else
+					try allowed (PMap.find cf.cf_name (if stat then c.cl_statics else c.cl_fields))
+					with Not_found -> false
 			)
 			|| (match c.cl_super with
 			| Some (csup,_) -> loop csup

+ 15 - 0
tests/unit/src/unit/issues/Issue10127.hx

@@ -0,0 +1,15 @@
+package unit.issues;
+
+@:allow(unit.issues.Issue10127)
+class Issue10127 extends Test {
+	static final privateField = true;
+
+	function test() {
+		accessible();
+		noAssert();
+	}
+}
+
+function accessible() {
+	Issue10127.privateField;
+}