Przeglądaj źródła

[matcher] fix assignment pattern display differently (closes #6395)

Simon Krajewski 8 lat temu
rodzic
commit
e6c9a6187b
2 zmienionych plików z 11 dodań i 9 usunięć
  1. 6 7
      src/typing/matcher.ml
  2. 5 2
      tests/display/src/cases/Issue6381.hx

+ 6 - 7
src/typing/matcher.ml

@@ -407,18 +407,17 @@ module Pattern = struct
 				) pctx1.current_locals;
 				PatOr(pat1,pat2)
 			| EBinop(OpAssign,e1,e2) ->
-				let pat = make pctx t e2 in
-				let rec loop e = match e with
+				let rec loop in_display e = match e with
 					| (EConst (Ident s),p) ->
 						let v = add_local s p in
+						if in_display then ignore(Typer.display_expr ctx e (mk (TLocal v) v.v_type p) (WithType t) p);
+						let pat = make pctx t e2 in
 						PatBind(v,pat)
-					| (EParenthesis e1,_) -> loop e1
-					| (EDisplay(e1,_),_) ->
-						ignore(Typer.handle_display ctx e (WithType t));
-						loop e
+					| (EParenthesis e1,_) -> loop in_display e1
+					| (EDisplay(e1,_),_) -> loop true e1
 					| _ -> fail()
 					in
-					loop e1
+					loop false e1
 			| EBinop(OpArrow,e1,e2) ->
 				let v = add_local "_" null_pos in
 				let e1 = type_expr ctx e1 Value in

+ 5 - 2
tests/display/src/cases/Issue6381.hx

@@ -7,13 +7,16 @@ class Issue6381 extends DisplayTestCase {
 	class Main {
 		public static function main() {
 			switch (Some(Some("foo"))) {
-				case Some(in{-1-}ner = Some(_)):
+				case Some({-1-}in{-2-}ner{-3-} = Some(_)):
+					{-4-}inner{-5-};
 				case _:
 			}
 		}
 	}
 	**/
 	function test() {
-		eq("haxe.ds.Option<String>", type(pos(1)));
+		eq("haxe.ds.Option<String>", type(pos(2)));
+		eq(range(1, 3), position(pos(2)));
+		eq(range(4, 5), usage(pos(2))[0]);
 	}
 }