Преглед изворни кода

respect `@:privateAccess` on AccNo (closes #4121)

Simon Krajewski пре 9 година
родитељ
комит
938ddf83b1
2 измењених фајлова са 13 додато и 2 уклоњено
  1. 11 0
      tests/unit/src/unit/issues/Issue4121.hx
  2. 2 2
      typer.ml

+ 11 - 0
tests/unit/src/unit/issues/Issue4121.hx

@@ -2,9 +2,20 @@ package unit.issues;
 
 import unit.issues.misc.Issue4121Macro.wrap;
 
+private typedef P2 = {
+	@:optional var hidden(null, null): Int;
+}
+
 class Issue4121 extends Test {
 	function test() {
 		eq("(@:test ((x) = (1)))", wrap(@:test x = 1));
 		eq("(@:test (@:test2 ((x) = (@:test3 (1)))))", wrap(@:test @:test2 x = @:test3 1));
+
+		var p2:P2 = { hidden: 12 };
+		t(unit.TestType.typeError(p2.hidden));
+		eq(12, @:privateAccess p2.hidden);
+		t(unit.TestType.typeError(p2.hidden = 13));
+		@:privateAccess p2.hidden = 13;
+		eq(13, @:privateAccess p2.hidden);
 	}
 }

+ 2 - 2
typer.ml

@@ -1173,7 +1173,7 @@ let field_access ctx mode f fmode t e p =
 		end
 	| Var v ->
 		match (match mode with MGet | MCall -> v.v_read | MSet -> v.v_write) with
-		| AccNo ->
+		| AccNo when not (Meta.has Meta.PrivateAccess ctx.meta) ->
 			(match follow e.etype with
 			| TInst (c,_) when is_parent c ctx.curclass || can_access ctx c { f with cf_public = false } false -> normal()
 			| TAnon a ->
@@ -1185,7 +1185,7 @@ let field_access ctx mode f fmode t e p =
 				| _ -> if ctx.untyped then normal() else AKNo f.cf_name)
 			| _ ->
 				if ctx.untyped then normal() else AKNo f.cf_name)
-		| AccNormal ->
+		| AccNormal | AccNo ->
 			(*
 				if we are reading from a read-only variable on an anonymous object, it might actually be a method, so make sure to create a closure
 			*)