Browse Source

Respect "private" on enum abstract values, closes #4904

Gama11 9 years ago
parent
commit
aded5ddfcf

+ 10 - 0
tests/misc/projects/Issue4904/Main.hx

@@ -0,0 +1,10 @@
+class Main {
+	static function main() {
+		TestAbstract.f;
+	}
+}
+
+@:enum
+abstract TestAbstract(Int) {
+	private var f = 0;
+}

+ 2 - 0
tests/misc/projects/Issue4904/compile.hxml

@@ -0,0 +1,2 @@
+-main Main
+--interp

+ 1 - 0
tests/misc/projects/Issue4904/compile.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:3: characters 2-16 : Cannot access private field f

+ 22 - 0
tests/unit/src/unit/issues/Issue4904.hx

@@ -0,0 +1,22 @@
+package unit.issues;
+
+class Issue4904 extends Test {
+	function test() {
+		eq(("A" : TestAbstract), TestAbstract.A);
+		eq(("B" : TestAbstract), TestAbstract.B);
+		eq((("C" : TestAbstract) : Int), -1);
+	}
+}
+
+@:enum
+abstract TestAbstract(Int) to Int {
+	var A = 0;
+	var B = 1;
+	private var Invalid = -1;
+
+	@:from public static function fromString(s:String) {
+		if (s == "A") return A;
+		if (s == "B") return B;
+		return Invalid;
+	}
+}

+ 1 - 1
typeload.ml

@@ -1839,7 +1839,7 @@ let build_enum_abstract ctx c a fields p =
 	List.iter (fun field ->
 		match field.cff_kind with
 		| FVar(ct,eo) when not (List.mem AStatic field.cff_access) ->
-			field.cff_access <- [AStatic;APublic];
+			field.cff_access <- [AStatic; if (List.mem APrivate field.cff_access) then APrivate else APublic];
 			field.cff_meta <- (Meta.Enum,[],field.cff_pos) :: (Meta.Impl,[],field.cff_pos) :: field.cff_meta;
 			let ct = match ct with
 				| Some _ -> ct