瀏覽代碼

Revert "[matcher] follow through static fields for value types (closes #4084)"

This reverts commit c189af425f9e867019a9625d442116c36d1a57fd.
Simon Krajewski 9 年之前
父節點
當前提交
62bcf793b1
共有 2 個文件被更改,包括 19 次插入45 次删除
  1. 19 28
      matcher.ml
  2. 0 17
      tests/unit/src/unit/issues/Issue4084.hx

+ 19 - 28
matcher.ml

@@ -323,26 +323,6 @@ let to_pattern ctx e t =
 		tctx.pc_locals <- PMap.add s (v,p) tctx.pc_locals;
 		v
 	in
-	let check_texpr_pattern e t p =
-		let ec = match Optimizer.make_constant_expression ctx ~concat_strings:true e with Some e -> e | None -> e in
-		match ec.eexpr with
-			| TField (_,FEnum (en,ef)) ->
-				begin try unify_raise ctx ec.etype t ec.epos with Error (Unify _,_) -> raise Not_found end;
-				begin try
-					unify_enum_field en (List.map (fun _ -> mk_mono()) en.e_params) ef t;
-				with Unify_error l ->
-					error (error_msg (Unify l)) p
-				end;
-				mk_con_pat (CEnum(en,ef)) [] t p
-			| TConst c | TCast({eexpr = TConst c},None) ->
-				begin try unify_raise ctx ec.etype t ec.epos with Error (Unify _,_) -> raise Not_found end;
-				unify ctx ec.etype t p;
-				mk_con_pat (CConst c) [] t p
-			| TTypeExpr mt ->
-				mk_type_pat ctx mt t p
-			| _ ->
-				raise Not_found
-	in
 	let rec loop pctx e t =
 		let p = pos e in
 		match fst e with
@@ -379,13 +359,7 @@ let to_pattern ctx e t =
 			| TTypeExpr mt ->
 				mk_type_pat ctx mt t p
 			| TField(_, FStatic(_,cf)) when is_value_type cf.cf_type ->
-				ignore (follow cf.cf_type);
-				begin match cf.cf_expr with
-				| Some e ->
-					(try check_texpr_pattern e t p with Not_found -> mk_con_pat (CExpr e) [] cf.cf_type p)
-				| None ->
-					mk_con_pat (CExpr e) [] cf.cf_type p
-				end
+				mk_con_pat (CExpr e) [] cf.cf_type p
 			| TField(_, FEnum(en,ef)) ->
 				begin try
 					unify_enum_field en (List.map (fun _ -> mk_mono()) en.e_params) ef t
@@ -472,7 +446,24 @@ let to_pattern ctx e t =
 						ctx.untyped <- old;
 						e
 				in
-				check_texpr_pattern ec t p
+				let ec = match Optimizer.make_constant_expression ctx ~concat_strings:true ec with Some e -> e | None -> ec in
+				(match ec.eexpr with
+					| TField (_,FEnum (en,ef)) ->
+						begin try unify_raise ctx ec.etype t ec.epos with Error (Unify _,_) -> raise Not_found end;
+						begin try
+							unify_enum_field en (List.map (fun _ -> mk_mono()) en.e_params) ef t;
+						with Unify_error l ->
+							error (error_msg (Unify l)) p
+						end;
+						mk_con_pat (CEnum(en,ef)) [] t p
+					| TConst c | TCast({eexpr = TConst c},None) ->
+						begin try unify_raise ctx ec.etype t ec.epos with Error (Unify _,_) -> raise Not_found end;
+						unify ctx ec.etype t p;
+						mk_con_pat (CConst c) [] t p
+					| TTypeExpr mt ->
+						mk_type_pat ctx mt t p
+					| _ ->
+						raise Not_found);
 			with Not_found ->
 				begin match get_tuple_params t with
 					| Some tl ->

+ 0 - 17
tests/unit/src/unit/issues/Issue4084.hx

@@ -1,17 +0,0 @@
-package unit.issues;
-
-class Issue4084 extends Test {
-	function test() {
-        var x = Xml.parse("<div>Hello!</div>");
-        var v = switch x.nodeType {
-            case Xml.ProcessingInstruction: 0;
-            case Xml.DocType: 1;
-            case Xml.Document: 2;
-            case Xml.CData: 3;
-            case Xml.PCData: 4;
-            case Xml.Element: 5;
-            case Xml.Comment: 6;
-        }
-		eq(2, v);
-	}
-}