add optional argument principality examples (#9405)

master
Jacques Garrigue 2020-03-31 13:52:22 +02:00 committed by GitHub
parent f8758a8bf8
commit e10e2bfa99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 0 deletions

View File

@ -33,3 +33,38 @@ Line 1, characters 4-23:
Error: This function should have type unit -> unit
but its first argument is labelled ?opt
|}];;
(* More examples *)
let f g = ignore (g ?x:(Some 2) ()); g ~x:3 () ;;
[%%expect{|
Line 1, characters 37-38:
1 | let f g = ignore (g ?x:(Some 2) ()); g ~x:3 () ;;
^
Error: This function is applied to arguments
in an order different from other calls.
This is only allowed when the real type is known.
|}]
let f g = let _ = g ?x:(Some 2) () in g ~x:3 () ;;
[%%expect{|
Line 1, characters 38-39:
1 | let f g = let _ = g ?x:(Some 2) () in g ~x:3 () ;;
^
Error: This function is applied to arguments
in an order different from other calls.
This is only allowed when the real type is known.
|}]
(* principality warning *)
let f g = ignore (g : ?x:int -> unit -> int); g ~x:3 () ;;
[%%expect{|
val f : (?x:int -> unit -> int) -> int = <fun>
|}, Principal{|
Line 1, characters 51-52:
1 | let f g = ignore (g : ?x:int -> unit -> int); g ~x:3 () ;;
^
Warning 18: using an optional argument here is not principal.
val f : (?x:int -> unit -> int) -> int = <fun>
|}]