-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use type annotations from arguments in let rec (#12315)
- Loading branch information
Showing
3 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
(* TEST | ||
expect; | ||
*) | ||
|
||
module M = struct type t = A | B end | ||
let rec f () = g A | ||
and g (x : M.t) = f () | ||
[%%expect{| | ||
module M : sig type t = A | B end | ||
val f : unit -> 'a = <fun> | ||
val g : M.t -> 'a = <fun> | ||
|}] | ||
|
||
let rec f () = g 42 | ||
and g (x : string) = f () | ||
[%%expect{| | ||
Line 1, characters 17-19: | ||
1 | let rec f () = g 42 | ||
^^ | ||
Error: This expression has type "int" but an expression was expected of type | ||
"string" | ||
|}] | ||
|
||
let rec opt_error ?(opt : string) () = f ?opt () | ||
[%%expect{| | ||
Line 1, characters 20-32: | ||
1 | let rec opt_error ?(opt : string) () = f ?opt () | ||
^^^^^^^^^^^^ | ||
Error: This pattern matches values of type "string" | ||
but a pattern was expected which matches values of type "'a option" | ||
|}] | ||
|
||
let rec opt_ok_f () = opt_ok_g ~foo:A () | ||
and opt_ok_g ?(foo : M.t option) () = opt_ok_f () | ||
[%%expect{| | ||
val opt_ok_f : unit -> 'a = <fun> | ||
val opt_ok_g : ?foo:M.t -> unit -> 'a = <fun> | ||
|}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters