Browse Source

print expected $type before typing

We usually want to see the value it initially has without any inference from the typing
Simon Krajewski 1 year ago
parent
commit
0c8a8e415d
1 changed files with 10 additions and 4 deletions
  1. 10 4
      src/typing/typer.ml

+ 10 - 4
src/typing/typer.ml

@@ -1740,13 +1740,19 @@ and type_call_builtin ctx e el mode with_type p =
 			| TFun signature -> type_bind ctx e signature args p
 			| _ -> raise Exit)
 	| (EConst (Ident "$type"),_) , e1 :: el ->
-		let e1 = type_expr ctx e1 with_type in
-		let s = s_type (print_context()) e1.etype in
-		let s = match el with
+		let expected = match el with
 			| [EConst (Ident "_"),_] ->
-				Printf.sprintf "%s (expected: %s)" s (WithType.to_string with_type)
+				Some (WithType.to_string with_type)
 			| _ ->
+				None
+		in
+		let e1 = type_expr ctx e1 with_type in
+		let s = s_type (print_context()) e1.etype in
+		let s = match expected with
+			| None ->
 				s
+			| Some s_expected ->
+				Printf.sprintf "%s (expected: %s)" s s_expected
 		in
 		warning ctx WInfo s e1.epos;
 		e1