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

support non-parenthesized label colon type equal optional in type dec… #2058

Merged
merged 1 commit into from
Jul 11, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions formatTest/unit_tests/expected_output/syntax.re
Original file line number Diff line number Diff line change
Expand Up @@ -1351,3 +1351,6 @@ foo(~a=?-1);
*/
let z = {<state: 0, x: y>};
let z = {<>};

/* https://github.com/facebook/reason/issues/2056 */
type foo = (~a: bool=?) => int;
15 changes: 9 additions & 6 deletions formatTest/unit_tests/input/syntax.re
Original file line number Diff line number Diff line change
Expand Up @@ -675,18 +675,18 @@ let myOptional (~a=?, ~b=?, ()) = 10;
type named = (~a: int=?, ~b: int=?, unit) => int;
/*F*/
let optionalAlias (~a as aa=?, ~b as bb=?, ()) = 10;
/*G*/
/*G*/
let optionalAnnot (~a as a:int =?, ~b as b:int=?, ()) = 10;
/*H*/
/*H*/
let optionalAliasAnnot (~a as aa:int =?, ~b as bb:int=?, ()) = 10;
/*I: */
/*I: */
let defOptional (~a as a=10, ~b as b=10, ()) = 10;
type named = (~a: int=?, ~b: int=?, unit) => int;
/*J*/
/*J*/
let defOptionalAlias (~a as aa=10, ~b as bb=10, ()) = 10;
/*K*/
/*K*/
let defOptionalAnnot (~a as a:int=10, ~b as b:int=10, ()) = 10;
/*L*/
/*L*/
let defOptionalAliasAnnot(~a as aa:int=10, ~b as bb:int=10, ()) = 10;

/*M: Invoking them - Punned */
Expand Down Expand Up @@ -1177,3 +1177,6 @@ foo(~a=?-1);
*/
let z = {<state: 0, x: y>};
let z = {<>};

/* https://github.com/facebook/reason/issues/2056 */
type foo = ~a:bool=? => int;
10 changes: 8 additions & 2 deletions src/reason-parser/reason_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -4308,17 +4308,23 @@ unattributed_core_type:
{ $1 }
| arrow_type_parameters EQUALGREATER core_type2
{ List.fold_right mktyp_arrow $1 $3 }
| as_loc(labelled_arrow_type_parameter_optional) EQUALGREATER core_type2
{ mktyp_arrow ($1, false) $3 }
| basic_core_type EQUALGREATER core_type2
{ mktyp (Ptyp_arrow (Nolabel, $1, $3)) }
;

labelled_arrow_type_parameter_optional:
| TILDE LIDENT COLON core_type EQUAL optional
{ ($6 $2, $4) }
;

arrow_type_parameter:
| core_type
{ (Nolabel, $1) }
| TILDE LIDENT COLON core_type
{ (Labelled $2, $4) }
| TILDE LIDENT COLON core_type EQUAL optional
{ ($6 $2, $4) }
| labelled_arrow_type_parameter_optional { $1 }
;

%inline uncurried_arrow_type_parameter:
Expand Down