瀏覽代碼

[typer] make `$type(_)` print the expected type

Simon Krajewski 4 年之前
父節點
當前提交
31b16a23fe
共有 1 個文件被更改,包括 10 次插入4 次删除
  1. 10 4
      src/typing/typer.ml

+ 10 - 4
src/typing/typer.ml

@@ -1594,10 +1594,16 @@ and type_call ?(mode=MGet) ctx e el (with_type:WithType.t) inline p =
 			| TFun signature -> type_bind ctx e signature args p
 			| _ -> def ())
 	| (EConst (Ident "$type"),_) , [e] ->
-		let e = type_expr ctx e WithType.value in
-		ctx.com.warning (s_type (print_context()) e.etype) e.epos;
-		let e = Diagnostics.secure_generated_code ctx e in
-		e
+		begin match fst e with
+		| EConst (Ident "_") ->
+			ctx.com.warning (WithType.to_string with_type) p;
+			mk (TConst TNull) t_dynamic p
+		| _ ->
+			let e = type_expr ctx e WithType.value in
+			ctx.com.warning (s_type (print_context()) e.etype) e.epos;
+			let e = Diagnostics.secure_generated_code ctx e in
+			e
+		end
 	| (EField(e,"match"),p), [epat] ->
 		let et = type_expr ctx e WithType.value in
 		let rec has_enum_match t = match follow t with