Skip to content

Commit 73d3810

Browse files
committed
experiment with allowing empty inline records
1 parent 182c6e8 commit 73d3810

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

jscomp/ml/typecore.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
12731273
| _ -> k None
12741274
end
12751275
| Ppat_record(lid_sp_list, closed) ->
1276-
assert (lid_sp_list <> []);
1276+
(*assert (lid_sp_list <> []);*)
12771277
let opath, record_ty =
12781278
try
12791279
let (p0, p, _, _) = extract_concrete_record !env expected_ty in

jscomp/syntax/src/res_core.ml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4544,7 +4544,6 @@ and parseConstrDeclArgs p =
45444544
(* TODO: this could use some cleanup/stratification *)
45454545
match p.Parser.token with
45464546
| Lbrace -> (
4547-
let lbrace = p.startPos in
45484547
Parser.next p;
45494548
let startPos = p.Parser.startPos in
45504549
match p.Parser.token with
@@ -4683,14 +4682,6 @@ and parseConstrDeclArgs p =
46834682
:: parseCommaDelimitedRegion ~grammar:Grammar.FieldDeclarations
46844683
~closing:Rbrace ~f:parseFieldDeclarationRegion p
46854684
in
4686-
let () =
4687-
match fields with
4688-
| [] ->
4689-
Parser.err ~startPos:lbrace p
4690-
(Diagnostics.message
4691-
"An inline record declaration needs at least one field")
4692-
| _ -> ()
4693-
in
46944685
Parser.expect Rbrace p;
46954686
Parser.optional p Comma |> ignore;
46964687
Parser.expect Rparen p;

jscomp/test/inline_record_test.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/inline_record_test.res

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,12 @@ let ff1 = (x: t1): t1 =>
117117
}
118118

119119
let () = Mt.from_pair_suites(__MODULE__, suites.contents)
120+
121+
type emptyRecord = A | B({})
122+
123+
let b = B({})
124+
125+
let () = switch b {
126+
| A => Js.log("A!")
127+
| B(_) => Js.log("B")
128+
}

0 commit comments

Comments
 (0)