From fba1f24b8d782d14d130f66fef3e519289957ea8 Mon Sep 17 00:00:00 2001 From: glennsl Date: Sun, 30 Jun 2024 23:12:23 +0200 Subject: [PATCH 1/2] fix(syntax): allow private in with constraints --- jscomp/syntax/src/res_core.ml | 8 ++++++-- .../tests/parsing/grammar/modtype/expected/with.res.txt | 1 + jscomp/syntax/tests/parsing/grammar/modtype/with.res | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/jscomp/syntax/src/res_core.ml b/jscomp/syntax/src/res_core.ml index e0c7cdf790..047b2c3ebd 100644 --- a/jscomp/syntax/src/res_core.ml +++ b/jscomp/syntax/src/res_core.ml @@ -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 *) diff --git a/jscomp/syntax/tests/parsing/grammar/modtype/expected/with.res.txt b/jscomp/syntax/tests/parsing/grammar/modtype/expected/with.res.txt index 20440e5fc1..535c2b6c3f 100644 --- a/jscomp/syntax/tests/parsing/grammar/modtype/expected/with.res.txt +++ b/jscomp/syntax/tests/parsing/grammar/modtype/expected/with.res.txt @@ -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) diff --git a/jscomp/syntax/tests/parsing/grammar/modtype/with.res b/jscomp/syntax/tests/parsing/grammar/modtype/with.res index aba2570315..4176b14284 100644 --- a/jscomp/syntax/tests/parsing/grammar/modtype/with.res +++ b/jscomp/syntax/tests/parsing/grammar/modtype/with.res @@ -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 From b7735de727808dbcaa2d25bbbb646db34482f1f4 Mon Sep 17 00:00:00 2001 From: glennsl Date: Sun, 30 Jun 2024 23:16:30 +0200 Subject: [PATCH 2/2] docs: add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8887ed37f8..8bbd24dc94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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