Browse Source

[display] don't show current pattern local in completion

closes #7319
Simon Krajewski 7 years ago
parent
commit
f41be5bd66
2 changed files with 31 additions and 0 deletions
  1. 10 0
      src/typing/matcher.ml
  2. 21 0
      tests/display/src/cases/Issue7319.hx

+ 10 - 0
src/typing/matcher.ml

@@ -464,6 +464,16 @@ module Pattern = struct
 				restore();
 				let pat = make pctx toplevel e1.etype e2 in
 				PatExtractor(v,e1,pat)
+			(* Special case for completion on a pattern local: We don't want to add the local to the context
+			   while displaying (#7319) *)
+			| EDisplay((EConst (Ident _),_ as e),dk) when pctx.ctx.com.display.dms_kind = DMDefault ->
+				let locals = ctx.locals in
+				let pat = loop e in
+				let locals' = ctx.locals in
+				ctx.locals <- locals;
+				ignore(TyperDisplay.handle_edisplay ctx e (if toplevel then DKPattern else dk) (WithType t));
+				ctx.locals <- locals';
+				pat
 			| EDisplay(e,dk) ->
 				let pat = loop e in
 				ignore(TyperDisplay.handle_edisplay ctx e (if toplevel then DKPattern else dk) (WithType t));

+ 21 - 0
tests/display/src/cases/Issue7319.hx

@@ -0,0 +1,21 @@
+package cases;
+
+class Issue7319 extends DisplayTestCase {
+	/**
+	import haxe.ds.Option;
+
+	class Main {
+		static function main() {
+			var option:Option<Int>;
+			switch option {
+				case None:
+				case So{-1-}
+			}
+		}
+	}
+	**/
+	function test() {
+		var fields = toplevel(pos(1));
+		eq(false, hasField(fields, "So", "haxe.ds.Option<Int>"));
+	}
+}