Skip to content

fix(syntax): allow private in with constraints #6843

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

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Add `rewatch` to the npm package as an alternative build tool. https://github.com/rescript-lang/rescript-compiler/pull/6762
- Throws an instance of JavaScript's `new Error()` and adds the extension payload for `cause` option. https://github.com/rescript-lang/rescript-compiler/pull/6611
- Allow free vars in types for type coercion `e :> t`. https://github.com/rescript-lang/rescript-compiler/pull/6828
- Allow `private` in with constraints. https://github.com/rescript-lang/rescript-compiler/pull/6843

#### :boom: Breaking Change

Expand Down
8 changes: 6 additions & 2 deletions jscomp/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6269,12 +6269,16 @@ and parse_with_constraint p =
(Location.mkloc (Longident.last type_constr.txt) type_constr.loc) )
| Equal ->
Parser.next p;
let private_flag =
if Parser.optional p Token.Private then Asttypes.Private
else Asttypes.Public
in
let typ_expr = parse_typ_expr p in
let type_constraints = parse_type_constraints p in
Parsetree.Pwith_type
( type_constr,
Ast_helper.Type.mk ~loc:type_constr.loc ~params ~manifest:typ_expr
~cstrs:type_constraints
Ast_helper.Type.mk ~loc:type_constr.loc ~priv:private_flag ~params
~manifest:typ_expr ~cstrs:type_constraints
(Location.mkloc (Longident.last type_constr.txt) type_constr.loc) )
| token ->
(* TODO: revisit *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module type A =
(Foo with type t = 'st constraint 'st = int constraint 'x = int and type
t = 'st constraint 'st = int constraint 'x = int and type t =
'st constraint 'st = int constraint 'x = int)
module type A = (Foo with type t = private string)
module type A = (Foo with type t := string)
module type A = (Foo with type 'a t := string)
module type A = (Foo with type ('a,'b) t := string)
Expand Down
1 change: 1 addition & 0 deletions jscomp/syntax/tests/parsing/grammar/modtype/with.res
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module type A = Foo
with type t = 'st constraint 'st = int constraint 'x = int
and type t = 'st constraint 'st = int constraint 'x = int
and type t = 'st constraint 'st = int constraint 'x = int
module type A = Foo with type t = private string

module type A = Foo with type t := string
module type A = Foo with type t<'a> := string
Expand Down