Selaa lähdekoodia

default to private for abstract methods (closes #2235)

Simon Krajewski 11 vuotta sitten
vanhempi
commit
cacaa12af5
3 muutettua tiedostoa jossa 22 lisäystä ja 2 poistoa
  1. 4 1
      genas3.ml
  2. 17 0
      tests/unit/issues/Issue2235.hx
  3. 1 1
      typeload.ml

+ 4 - 1
genas3.ml

@@ -947,7 +947,10 @@ let generate_field ctx static f =
 		| _ -> ()
 	) f.cf_meta;
 	let public = f.cf_public || Hashtbl.mem ctx.get_sets (f.cf_name,static) || (f.cf_name = "main" && static)
-	    || f.cf_name = "resolve" || Ast.Meta.has Ast.Meta.Public f.cf_meta || (match ctx.curclass.cl_kind with KAbstractImpl _ -> Ast.Meta.has Ast.Meta.Op f.cf_meta | _ -> false) in
+	    || f.cf_name = "resolve" || Ast.Meta.has Ast.Meta.Public f.cf_meta
+	    (* consider all abstract methods public to avoid issues with inlined private access *)
+	    || (match ctx.curclass.cl_kind with KAbstractImpl _ -> true | _ -> false)
+	in
 	let rights = (if static then "static " else "") ^ (if public then "public" else "protected") in
 	let p = ctx.curclass.cl_pos in
 	match f.cf_expr, f.cf_kind with

+ 17 - 0
tests/unit/issues/Issue2235.hx

@@ -0,0 +1,17 @@
+package unit.issues;
+import unit.Test;
+
+private abstract A(Int) from Int {
+    function f() {}
+    static function fs() {}
+}
+
+class Issue2235 extends Test {
+	function test() {
+        var a:A = 0;
+        t(unit.TestType.typeError(a.f()));
+        t(unit.TestType.typeError(a.f));
+		t(unit.TestType.typeError(A.fs()));
+		t(unit.TestType.typeError(A.fs));
+	}
+}

+ 1 - 1
typeload.ml

@@ -1499,7 +1499,7 @@ let init_class ctx c p context_init herits fields =
 			true
 		else match parent with
 			| Some { cf_public = p } -> p
-			| _ -> c.cl_extern || c.cl_interface || extends_public || (ctx.com.version < 30200 && match c.cl_kind with KAbstractImpl _ -> true | _ -> false)
+			| _ -> c.cl_extern || c.cl_interface || extends_public
 	in
 	let rec get_parent c name =
 		match c.cl_super with