瀏覽代碼

make enum constructor pattern typing more accurate

Simon Krajewski 9 年之前
父節點
當前提交
e8c7422e56

+ 1 - 0
src/typing/matcher.ml

@@ -279,6 +279,7 @@ module Pattern = struct
 				let v = add_local s in
 				let v = add_local s in
 				PatVariable v
 				PatVariable v
 			| ECall(e1,el) ->
 			| ECall(e1,el) ->
+				let t = tfun (List.map (fun _ -> mk_mono()) el) t in
 				let e1 = type_expr ctx e1 (WithType t) in
 				let e1 = type_expr ctx e1 (WithType t) in
 				begin match e1.eexpr,follow e1.etype with
 				begin match e1.eexpr,follow e1.etype with
 					| TField(_, FEnum(en,ef)),TFun(_,TEnum(_,tl)) ->
 					| TField(_, FEnum(en,ef)),TFun(_,TEnum(_,tl)) ->

+ 3 - 0
src/typing/typer.ml

@@ -4003,6 +4003,9 @@ and maybe_type_against_enum ctx f with_type p =
 						| [t] -> loop t
 						| [t] -> loop t
 						| _ -> raise Exit
 						| _ -> raise Exit
 					end
 					end
+				(* We might type against an enum constructor. *)
+				| TFun(_,tr) ->
+					loop tr
 				| _ ->
 				| _ ->
 					raise Exit
 					raise Exit
 			in
 			in

+ 1 - 0
tests/misc/projects/Issue5118/compile1.hxml

@@ -0,0 +1 @@
+--display Main.hx@156@type

+ 3 - 0
tests/misc/projects/Issue5118/compile1.hxml.stderr

@@ -0,0 +1,3 @@
+<type>
+v : Int -&gt; haxe.ds.Option&lt;Int&gt;
+</type>

+ 0 - 0
tests/misc/projects/Issue5118/compile.hxml → tests/misc/projects/Issue5118/compile2.hxml


+ 0 - 0
tests/misc/projects/Issue5118/compile.hxml.stderr → tests/misc/projects/Issue5118/compile2.hxml.stderr