Skip to content

Commit 60f3e16

Browse files
authored
fix(syntax): allow private in with constraints (#6843)
* fix(syntax): allow private in with constraints * docs: add changelog entry
1 parent 0197ea5 commit 60f3e16

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Add `rewatch` to the npm package as an alternative build tool. https://github.com/rescript-lang/rescript-compiler/pull/6762
1919
- 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
2020
- Allow free vars in types for type coercion `e :> t`. https://github.com/rescript-lang/rescript-compiler/pull/6828
21+
- Allow `private` in with constraints. https://github.com/rescript-lang/rescript-compiler/pull/6843
2122

2223
#### :boom: Breaking Change
2324

jscomp/syntax/src/res_core.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6269,12 +6269,16 @@ and parse_with_constraint p =
62696269
(Location.mkloc (Longident.last type_constr.txt) type_constr.loc) )
62706270
| Equal ->
62716271
Parser.next p;
6272+
let private_flag =
6273+
if Parser.optional p Token.Private then Asttypes.Private
6274+
else Asttypes.Public
6275+
in
62726276
let typ_expr = parse_typ_expr p in
62736277
let type_constraints = parse_type_constraints p in
62746278
Parsetree.Pwith_type
62756279
( type_constr,
6276-
Ast_helper.Type.mk ~loc:type_constr.loc ~params ~manifest:typ_expr
6277-
~cstrs:type_constraints
6280+
Ast_helper.Type.mk ~loc:type_constr.loc ~priv:private_flag ~params
6281+
~manifest:typ_expr ~cstrs:type_constraints
62786282
(Location.mkloc (Longident.last type_constr.txt) type_constr.loc) )
62796283
| token ->
62806284
(* TODO: revisit *)

jscomp/syntax/tests/parsing/grammar/modtype/expected/with.res.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module type A =
99
(Foo with type t = 'st constraint 'st = int constraint 'x = int and type
1010
t = 'st constraint 'st = int constraint 'x = int and type t =
1111
'st constraint 'st = int constraint 'x = int)
12+
module type A = (Foo with type t = private string)
1213
module type A = (Foo with type t := string)
1314
module type A = (Foo with type 'a t := string)
1415
module type A = (Foo with type ('a,'b) t := string)

jscomp/syntax/tests/parsing/grammar/modtype/with.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module type A = Foo
88
with type t = 'st constraint 'st = int constraint 'x = int
99
and type t = 'st constraint 'st = int constraint 'x = int
1010
and type t = 'st constraint 'st = int constraint 'x = int
11+
module type A = Foo with type t = private string
1112

1213
module type A = Foo with type t := string
1314
module type A = Foo with type t<'a> := string

0 commit comments

Comments
 (0)