Skip to content
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

Pattern matching for dicts #7059

Merged
merged 31 commits into from
Oct 2, 2024
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
35d0e09
Draft dict pattern matching.
cristianoc Feb 2, 2024
ed30f68
Avoid mis-firing when a field is legit missing.
cristianoc Feb 2, 2024
5b93ca1
Make lbl_all mutable.
cristianoc Feb 2, 2024
011b3bb
Add test for the various aspects of first class dicts.
cristianoc Feb 8, 2024
a4e809a
update tests
cristianoc Feb 8, 2024
1a079a4
make builtin dict type be a record with anyOtherField catch all
zth Sep 29, 2024
9c4c091
make typechecker account for res.dictPattern attribute to infer recor…
zth Sep 29, 2024
09f07f2
format
zth Sep 29, 2024
35a6dad
add some tests, and disallow direct record field access on dicts
zth Sep 30, 2024
a2d09fa
make code path handling the magic record field for dicts just work on…
zth Sep 30, 2024
f783d20
remove now irrelevant test since we reduced scope to just focus on di…
zth Sep 30, 2024
f134c62
remove lingering file
zth Sep 30, 2024
b1ebde4
format
zth Sep 30, 2024
6510847
make sure coercion is disallowed for dicts
zth Sep 30, 2024
4073eb0
add internal test making sure dict labels dont stack
zth Sep 30, 2024
768814f
add more fields to test
zth Sep 30, 2024
828b01c
comment + rename file
zth Sep 30, 2024
821bd2d
share a few definitions
zth Sep 30, 2024
ae1ff05
no need to check tvar
zth Sep 30, 2024
c558771
remove comment
zth Sep 30, 2024
f91c04c
add more comments
zth Sep 30, 2024
00dd136
syntax support
zth Sep 30, 2024
db29437
cleanup
zth Sep 30, 2024
d4df2f8
add broken dict pattern parsing test
zth Oct 1, 2024
01132d3
fix pattern matching of dict
tsnobip Oct 1, 2024
849d950
comments and changelog
zth Oct 1, 2024
c082baa
a few more comment tests
zth Oct 1, 2024
9fa2193
undo changelog formatting
zth Oct 1, 2024
81b11ec
fixes
zth Oct 2, 2024
02c12f1
simplify
zth Oct 2, 2024
3d42ed0
add live attribute suppressing dead code analysis for dicts since the…
zth Oct 2, 2024
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
Prev Previous commit
Next Next commit
cleanup
zth committed Oct 1, 2024
commit db294378d5d9a5da0c2ae921bc3b7ca9a7496129
51 changes: 25 additions & 26 deletions jscomp/syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
@@ -2602,34 +2602,33 @@ and print_pattern_record_row ~state row cmt_tbl =
print_comments doc cmt_tbl loc_for_comments

and print_pattern_dict_row ~state
(row : Longident.t Location.loc * Parsetree.pattern) cmt_tbl =
match row with
| longident, pattern ->
let loc_for_comments =
{longident.loc with loc_end = pattern.ppat_loc.loc_end}
in
let rhs_doc =
let doc = print_pattern ~state pattern cmt_tbl in
let doc =
if Parens.pattern_record_row_rhs pattern then add_parens doc else doc
in
Doc.concat [print_optional_label pattern.ppat_attributes; doc]
in
let lbl_doc =
Doc.concat [Doc.text "\""; print_longident longident.txt; Doc.text "\""]
in
((longident, pattern) : Longident.t Location.loc * Parsetree.pattern)
cmt_tbl =
let loc_for_comments =
{longident.loc with loc_end = pattern.ppat_loc.loc_end}
in
let rhs_doc =
let doc = print_pattern ~state pattern cmt_tbl in
let doc =
Doc.group
(Doc.concat
[
lbl_doc;
Doc.text ":";
(if ParsetreeViewer.is_huggable_pattern pattern then
Doc.concat [Doc.space; rhs_doc]
else Doc.indent (Doc.concat [Doc.line; rhs_doc]));
])
if Parens.pattern_record_row_rhs pattern then add_parens doc else doc
in
print_comments doc cmt_tbl loc_for_comments
Doc.concat [print_optional_label pattern.ppat_attributes; doc]
in
let lbl_doc =
Doc.concat [Doc.text "\""; print_longident longident.txt; Doc.text "\""]
in
let doc =
Doc.group
(Doc.concat
[
lbl_doc;
Doc.text ":";
(if ParsetreeViewer.is_huggable_pattern pattern then
Doc.concat [Doc.space; rhs_doc]
else Doc.indent (Doc.concat [Doc.line; rhs_doc]));
])
in
print_comments doc cmt_tbl loc_for_comments

and print_expression_with_comments ~state expr cmt_tbl : Doc.t =
let doc = print_expression ~state expr cmt_tbl in