Browse Source

[flash] consider extern classes when figuring out whether we need a protected namespace (closes #8248)

Dan Korostelev 6 years ago
parent
commit
0ddea08a12
2 changed files with 19 additions and 0 deletions
  1. 10 0
      src/generators/genswf9.ml
  2. 9 0
      tests/unit/src/unit/issues/Issue8248.hx

+ 10 - 0
src/generators/genswf9.ml

@@ -2588,6 +2588,16 @@ let generate_class ctx c =
 		if Meta.has has_protected_meta csup.cl_meta then begin
 			has_protected := Some (make_class_ns c);
 			mark_has_protected c (* also mark this class with the meta for further child classes *)
+		end else if csup.cl_extern then begin
+			let rec loop csup =
+				if List.exists (fun cf -> Meta.has Meta.Protected cf.cf_meta) csup.cl_ordered_fields then begin
+					has_protected := Some (make_class_ns c);
+					mark_has_protected c; (* also mark this class with the meta for further child classes *)
+					mark_has_protected csup; (* ALSO mark the extern class for faster future checks *)
+				end else
+					Option.may (fun (csup,_) -> loop csup) csup.cl_super;
+			in
+			loop csup
 		end
 	) c.cl_super;
 	{

+ 9 - 0
tests/unit/src/unit/issues/Issue8248.hx

@@ -19,12 +19,21 @@ private class Child extends Base {
 private class GrandChild extends Child {
 	override function f() return 2;
 }
+
+private class ExternChild extends Lib {}
+private class ExternGrandChild extends ExternChild {
+	@:protected // TODO: should we generate `protected` automatically here?
+	override function f() return "bye";
+
+	public function getF() return f();
+}
 #end
 
 class Issue8248 extends unit.Test {
 	#if flash
 	function test() {
 		eq(new GrandChild().x, 2);
+		eq(new ExternGrandChild().getF(), "bye");
 	}
 	#end
 }