Skip to content

Pattern matching for dicts #7059

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

Merged
merged 31 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
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
Add test for the various aspects of first class dicts.
  • Loading branch information
cristianoc authored and zth committed Oct 1, 2024
commit 011b3bb7a9bc4decf8af8552a17f82b49041aa4d
69 changes: 69 additions & 0 deletions jscomp/test/FirstClassDicts.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions jscomp/test/FirstClassDicts.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module CreateAndLookup = {
type myDict = {name?: string, mutable anyOtherField?: int}

let test_create: myDict = {name: "hello", something: 5}

let test_lookup = (d: myDict) => d.something = Some(10)
}


module Update = {
type myDict = {name?: string, mutable anyOtherField?: int}

let test_update = (d: myDict) => d.something = Some(10)
}


module PatternMatching = {
type myDict = {name?: string, anyOtherField?: int}

let tst1 = (d: myDict) =>
switch d {
| {name: n, something: i} => String.length(n) + i
| {name: n} => String.length(n)
| {something: i} => i
| _ => 0
}

let tst2 = (d: myDict) =>
switch d {
| {name: _, a: i, b: j} => i + j
| _ => 0
}
}
Loading