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

Exclude private fields from import (#10704)

* Exclude private fields from import

* Use can_access

* Add test

* Test fix
RblSb пре 3 година
родитељ
комит
3b2030d0ff

+ 3 - 1
src/context/display/displayToplevel.ml

@@ -400,7 +400,9 @@ let collect ctx tk with_type sort =
 						| _ -> TClassDecl c,make_ci_class_field
 						| _ -> TClassDecl c,make_ci_class_field
 					in
 					in
 					let origin = StaticImport decl in
 					let origin = StaticImport decl in
-					add (make (CompletionClassField.make cf CFSStatic origin is_qualified) (tpair ~values:(get_value_meta cf.cf_meta) cf.cf_type)) (Some name)
+					if can_access ctx c cf true && not (Meta.has Meta.NoCompletion cf.cf_meta) then begin
+						add (make (CompletionClassField.make cf CFSStatic origin is_qualified) (tpair ~values:(get_value_meta cf.cf_meta) cf.cf_type)) (Some name)
+					end
 				in
 				in
 				match resolve_typedef mt with
 				match resolve_typedef mt with
 					| TClassDecl c -> class_import c;
 					| TClassDecl c -> class_import c;

+ 17 - 0
tests/display/src/cases/Issue10704.hx

@@ -0,0 +1,17 @@
+package cases;
+
+class Issue10704 extends DisplayTestCase {
+	/**
+		import misc.issue10704.Statics.*;
+		class Main {
+			static function main() {
+				foo{-1-}
+			}
+		}
+	**/
+	function test() {
+		eq(true, hasToplevel(toplevel(pos(1)), "static", "fooPublic"));
+		eq(false, hasToplevel(toplevel(pos(1)), "static", "fooNoCompletion"));
+		eq(false, hasToplevel(toplevel(pos(1)), "static", "fooPrivate"));
+	}
+}

+ 10 - 0
tests/display/src/misc/issue10704/Statics.hx

@@ -0,0 +1,10 @@
+package misc.issue10704;
+
+class Statics {
+	public static final fooPublic = 0;
+
+	@:noCompletion
+	public static final fooNoCompletion = 0;
+
+	static final fooPrivate = 0;
+}