summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremie Dimino <jdimino@janestreet.com>2015-11-05 10:26:15 +0000
committerJeremie Dimino <jdimino@janestreet.com>2015-11-05 10:41:13 +0000
commit6676784f6320aa9e415261fca1154c5447fa7a13 (patch)
tree8e7648eddbe6195d6b6a1819e3eca0b2132e4265
parent26657d5736b1b663072ea9ca17957875b909286d (diff)
downloadocaml-6676784f6320aa9e415261fca1154c5447fa7a13.tar.gz
PR#6806: Allow type annotations before the "->" in "fun <args> -> <expr>"
Patch by Valentin Gatien-Baron
-rw-r--r--Changes2
-rw-r--r--parsing/parser.mly3
-rw-r--r--testsuite/tests/typing-warnings/coercions.ml2
3 files changed, 5 insertions, 2 deletions
diff --git a/Changes b/Changes
index 06d0bb2887..c37d387b09 100644
--- a/Changes
+++ b/Changes
@@ -51,6 +51,8 @@ Language features:
(Pierre Chambart, Mark Shinwell)
- PR#6806: Syntax shortcut for putting a type annotation on a record field
(Valentin Gatien-Baron, review by Jérémie Dimino)
+- PR#6806: Allow type annotations before the "->" in "fun <args> -> <expr>"
+ (Valentin Gatien-Baron, review by Jérémie Dimino)
Compilers:
- PR#4800: better compilation of tuple assignment (Gabriel Scherer and
diff --git a/parsing/parser.mly b/parsing/parser.mly
index 10296e7cdb..6210cc5d3d 100644
--- a/parsing/parser.mly
+++ b/parsing/parser.mly
@@ -1557,7 +1557,8 @@ match_case:
{ Exp.case $1 (Exp.unreachable ~loc:(rhs_loc 3) ())}
;
fun_def:
- MINUSGREATER seq_expr { $2 }
+ MINUSGREATER seq_expr { $2 }
+ | COLON simple_core_type MINUSGREATER seq_expr { mkexp (Pexp_constraint ($4, $2)) }
/* Cf #5939: we used to accept (fun p when e0 -> e) */
| labeled_simple_pattern fun_def
{
diff --git a/testsuite/tests/typing-warnings/coercions.ml b/testsuite/tests/typing-warnings/coercions.ml
index 1ca390b28e..d5126e916c 100644
--- a/testsuite/tests/typing-warnings/coercions.ml
+++ b/testsuite/tests/typing-warnings/coercions.ml
@@ -2,4 +2,4 @@
fun b -> if b then format_of_string "x" else "y";;
fun b -> if b then "x" else format_of_string "y";;
-fun b -> (if b then "x" else "y" : (_,_,_) format);;
+fun b : (_,_,_) format -> if b then "x" else "y";;