Browse Source

don't `@:forward` shadowed fields for completion
fixes #8558

Aleksandr Kuzmenko 6 years ago
parent
commit
b2b777b1bd
2 changed files with 29 additions and 1 deletions
  1. 4 1
      src/context/display/displayFields.ml
  2. 25 0
      tests/display/src/cases/Issue8558.hx

+ 4 - 1
src/context/display/displayFields.ml

@@ -171,8 +171,11 @@ let collect ctx e_ast e dk with_type p =
 					| _ -> None
 				) el in
 				let forwarded_fields = loop PMap.empty (apply_params a.a_params tl a.a_this) in
+				let abstract_has_own_field field_name =
+					PMap.mem field_name c.cl_fields || PMap.mem field_name c.cl_statics
+				in
 				PMap.foldi (fun name item acc ->
-					if sl = [] || List.mem name sl && is_new_item acc name then
+					if (sl = [] || List.mem name sl && is_new_item acc name) && not (abstract_has_own_field name) then
 						PMap.add name item acc
 					else
 						acc

+ 25 - 0
tests/display/src/cases/Issue8558.hx

@@ -0,0 +1,25 @@
+package cases;
+
+class Issue8558 extends DisplayTestCase {
+	/**
+		class Life {
+			public function new () {}
+			public var die:Int;
+		}
+
+		@:forward abstract Immortal(Life) from Life {
+			private var die(get,never):Int;
+			function get_die() return 0;
+		}
+
+		class Main {
+			static function main() {
+				var bar:Immortal = new Life();
+				bar.{-1-}
+			}
+		}
+	**/
+	function testAbstractShadowsForwardedField() {
+		eq(false, hasField(fields(pos(1)), "die", "Int"));
+	}
+}