소스 검색

deal with EDisplay in assignment patterns (closes #6381)

Simon Krajewski 8 년 전
부모
커밋
19f7d20911
2개의 변경된 파일31개의 추가작업 그리고 3개의 파일을 삭제
  1. 12 3
      src/typing/matcher.ml
  2. 19 0
      tests/display/src/cases/Issue6381.hx

+ 12 - 3
src/typing/matcher.ml

@@ -406,10 +406,19 @@ module Pattern = struct
 					pctx.current_locals <- PMap.add name (v,p) pctx.current_locals
 				) pctx1.current_locals;
 				PatOr(pat1,pat2)
-			| EBinop(OpAssign,(EConst (Ident s),p),e2) ->
+			| EBinop(OpAssign,e1,e2) ->
 				let pat = make pctx t e2 in
-				let v = add_local s p in
-				PatBind(v,pat)
+				let rec loop e = match e with
+					| (EConst (Ident s),p) ->
+						let v = add_local s p in
+						PatBind(v,pat)
+					| (EParenthesis e1,_) -> loop e1
+					| (EDisplay(e1,_),_) ->
+						ignore(Typer.handle_display ctx e (WithType t));
+						loop e
+					| _ -> fail()
+					in
+					loop e1
 			| EBinop(OpArrow,e1,e2) ->
 				let v = add_local "_" null_pos in
 				let e1 = type_expr ctx e1 Value in

+ 19 - 0
tests/display/src/cases/Issue6381.hx

@@ -0,0 +1,19 @@
+package cases;
+
+class Issue6381 extends DisplayTestCase {
+	/**
+	import haxe.ds.Option;
+
+	class Main {
+		public static function main() {
+			switch (Some(Some("foo"))) {
+				case Some(in{-1-}ner = Some(_)):
+				case _:
+			}
+		}
+	}
+	**/
+	function test() {
+		eq("haxe.ds.Option<String>", type(pos(1)));
+	}
+}