New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specific explanation for unification errors involving functions of type unit -> _ #1505

Merged
merged 3 commits into from Dec 3, 2017
Jump to file or symbol
Failed to load files and symbols.
+58 −0
Diff settings

Always

Just for now

Viewing a subset of changes. View all

Add tests

  • Loading branch information...
Armael committed Nov 30, 2017
commit 25bb9ca7e0a24e4bf41023386ae43e8c7232764d
@@ -14,5 +14,6 @@
#########################################################################
BASEDIR=../..
EXPECT_FLAGS=-strict-sequence
include $(BASEDIR)/makefiles/Makefile.expect
include $(BASEDIR)/makefiles/Makefile.common
@@ -0,0 +1,57 @@
let g f = f ()
let _ = g 3;; (* missing `fun () ->' *)
[%%expect{|
val g : (unit -> 'a) -> 'a = <fun>
Line _, characters 10-11:
Error: This expression has type int but an expression was expected of type
unit -> 'a
Hint: Did you forget to wrap the expression using `fun () ->'?
|}];;
let _ =
print_int 3;
print_newline; (* missing unit argument *)
print_int 5;;
(* We use -strict-sequence for this test: otherwise only a warning is produced
about print_newline not being of type unit *)
[%%expect{|
Line _, characters 3-16:
Error: This expression has type unit -> unit
but an expression was expected of type unit
Hint: Did you forget to provide `()' as argument?
|}];;
let x = read_int in (* missing unit argument *)
print_int x;;
[%%expect{|
Line _, characters 10-11:
Error: This expression has type unit -> int
but an expression was expected of type int
Hint: Did you forget to provide `()' as argument?
|}];;
let g f =
let _ = f () in
f = 3;;
[%%expect{|
Line _, characters 6-7:
Error: This expression has type int but an expression was expected of type
unit -> 'a
Hint: Did you forget to wrap the expression using `fun () ->'?
|}];;
let g f =
let _ = f () in
3 = f;;
[%%expect{|
Line _, characters 6-7:
Error: This expression has type unit -> 'a
but an expression was expected of type int
Hint: Did you forget to provide `()' as argument?
|}]
ProTip! Use n and p to navigate between commits in a pull request.