Skip to content
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

Pun labelled arguments with type constraint in function applications #10434

Merged
merged 8 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changes
Expand Up @@ -25,6 +25,9 @@ Working version
64-bit floats in Cmm.memory_chunk.
(Greta Yorsh, review by Xavier Leroy)

- #10434: Pun labelled arguments with type constraint in function applications.
(Greta Yorsh, review by Nicolas Chataing and Nicolás Ojeda Bär)

### Build system:

### Bug fixes:
Expand Down
5,738 changes: 2,899 additions & 2,839 deletions boot/menhir/parser.ml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions parsing/parser.mly
Expand Up @@ -2467,6 +2467,9 @@ labeled_simple_expr:
| TILDE label = LIDENT
{ let loc = $loc(label) in
(Labelled label, mkexpvar ~loc label) }
| TILDE LPAREN label = LIDENT ty = type_constraint RPAREN
{ (Labelled label, mkexp_constraint ~loc:($startpos($2), $endpos)
(mkexpvar ~loc:$loc(label) label) ty) }
| QUESTION label = LIDENT
{ let loc = $loc(label) in
(Optional label, mkexpvar ~loc label) }
Expand Down
60 changes: 60 additions & 0 deletions testsuite/tests/parsetree/locations_test.compilers.reference
Expand Up @@ -1308,4 +1308,64 @@ Ptop_def
]

- : < f : int > = <obj>
Ptop_def
[
structure_item (//toplevel//[3,66+0]..[5,98+12])
Pstr_value Nonrec
[
<def>
pattern (//toplevel//[3,66+4]..[3,66+5])
Ppat_var "g" (//toplevel//[3,66+4]..[3,66+5])
expression (//toplevel//[3,66+6]..[5,98+12]) ghost
Pexp_fun
Nolabel
None
pattern (//toplevel//[3,66+6]..[3,66+7])
Ppat_var "y" (//toplevel//[3,66+6]..[3,66+7])
expression (//toplevel//[4,76+2]..[5,98+12])
Pexp_let Nonrec
[
<def>
pattern (//toplevel//[4,76+6]..[4,76+7])
Ppat_var "f" (//toplevel//[4,76+6]..[4,76+7])
expression (//toplevel//[4,76+8]..[4,76+18]) ghost
Pexp_fun
Labelled "y"
None
pattern (//toplevel//[4,76+9]..[4,76+10])
Ppat_var "y" (//toplevel//[4,76+9]..[4,76+10])
expression (//toplevel//[4,76+13]..[4,76+18])
Pexp_apply
expression (//toplevel//[4,76+15]..[4,76+16])
Pexp_ident "+" (//toplevel//[4,76+15]..[4,76+16])
[
<arg>
Nolabel
expression (//toplevel//[4,76+13]..[4,76+14])
Pexp_ident "y" (//toplevel//[4,76+13]..[4,76+14])
<arg>
Nolabel
expression (//toplevel//[4,76+17]..[4,76+18])
Pexp_constant PConst_int (1,None)
]
]
expression (//toplevel//[5,98+2]..[5,98+12])
Pexp_apply
expression (//toplevel//[5,98+2]..[5,98+3])
Pexp_ident "f" (//toplevel//[5,98+2]..[5,98+3])
[
<arg>
Labelled "y"
expression (//toplevel//[5,98+5]..[5,98+12]) ghost
Pexp_constraint
expression (//toplevel//[5,98+6]..[5,98+7])
Pexp_ident "y" (//toplevel//[5,98+6]..[5,98+7])
core_type (//toplevel//[5,98+8]..[5,98+11])
Ptyp_constr "int" (//toplevel//[5,98+8]..[5,98+11])
[]
]
]
]

val g : int -> int = <fun>

6 changes: 6 additions & 0 deletions testsuite/tests/parsetree/locations_test.ml
Expand Up @@ -122,3 +122,9 @@ f object method f = 1 end
object method f = 1 end # f
object end
;;

(* Punning of labelled function argument with type constraint *)
let g y =
let f ~y = y + 1 in
f ~(y:int)
;;
6 changes: 5 additions & 1 deletion testsuite/tests/parsetree/source.ml
Expand Up @@ -7436,4 +7436,8 @@ let f x y z = x in
f object method f = 1 end
object method f = 1 end # f
object end
;;

(* Punning of labelled function argument with type constraint *)
let g y =
let f ~y = y + 1 in
f ~(y:int)