Skip to content

Commit e63147f

Browse files
committed
In module declaration treat M = { as if it were M : {
1 parent 4a2c1b1 commit e63147f

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
- Remove deprecated pipe last (`|>`) syntax. https://github.com/rescript-lang/rescript/pull/7512
3737
- Improve error message for pipe (`->`) syntax. https://github.com/rescript-lang/rescript/pull/7520
3838
- Improve a few error messages around various subtyping issues. https://github.com/rescript-lang/rescript/pull/7404
39+
- In module declarations, accept the invalid syntax `M = {...}` and format it to `M : {...}`. https://github.com/rescript-lang/rescript/pull/7527
40+
41+
#### :house: Internal
42+
3943
- Refactor the ast for record expressions and patterns. https://github.com/rescript-lang/rescript/pull/7528
4044

4145
# 12.0.0-alpha.13

compiler/syntax/src/res_core.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6541,10 +6541,15 @@ and parse_module_declaration_or_alias ~attrs p =
65416541
| Colon ->
65426542
Parser.next p;
65436543
parse_module_type p
6544-
| Equal ->
6544+
| Equal -> (
65456545
Parser.next p;
6546-
let lident = parse_module_long_ident ~lowercase:false p in
6547-
Ast_helper.Mty.alias lident
6546+
match p.Parser.token with
6547+
| Lbrace ->
6548+
(* Parse `module M = {` as `module M : {` *)
6549+
parse_module_type p
6550+
| _ ->
6551+
let lident = parse_module_long_ident ~lowercase:false p in
6552+
Ast_helper.Mty.alias lident)
65486553
| token ->
65496554
Parser.err p (Diagnostics.unexpected token p.breadcrumbs);
65506555
Recover.default_module_type ()

tests/syntax_tests/data/printer/signature/expected/module.resi.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ module LongNaaaaame: MyModule
2323

2424
@attr
2525
module LinkedList: module type of List
26+
27+
// turn `=` into `:`
28+
module M: {
29+
let x: int
30+
}

tests/syntax_tests/data/printer/signature/module.resi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ module LongNaaaaame: MyModule
2424

2525
@attr
2626
module LinkedList: module type of List
27+
28+
// turn `=` into `:`
29+
module M = { let x: int }

0 commit comments

Comments
 (0)