Skip to content

Commit

Permalink
feat(compiler): Improve warning when omitting fields in record pattern (
Browse files Browse the repository at this point in the history
#2079)

Co-authored-by: Oscar Spencer <oscar.spen@gmail.com>
  • Loading branch information
spotandjake and ospencer committed Mar 28, 2024
1 parent 7eadfb0 commit 4a929fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion compiler/src/utils/warnings.re
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ let message =
msg,
)
| NonClosedRecordPattern(s) =>
"the following fields are missing from the record pattern: " ++ s
"the following fields are missing from the record pattern: "
++ s
++ "\nUse `_` to ignore unused fields."
| FuncWasmUnsafe(func, f, m) =>
"it looks like you are using "
++ func
Expand Down
12 changes: 11 additions & 1 deletion compiler/test/suites/records.re
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ describe("records", ({test, testSkip}) => {
"record Rec {foo: Number, bar: Number}; let a = {foo: 1, bar: 2}; let b = {...a, foo: 2, bar: 3}",
Warnings.UselessRecordSpread,
);

assertWarning(
"disambiguation_1",
{|
Expand All @@ -256,4 +255,15 @@ describe("records", ({test, testSkip}) => {
(x: B) => x.field
|},
);
// well_formedness field omission warning
assertWarning(
"record_field_omit_1",
"record Rec {foo: Number, bar: Number}; let a = {foo: 1, bar: 2}; match (a) { { foo } => void, _ => void }",
Warnings.NonClosedRecordPattern("bar"),
);
assertWarning(
"record_field_omit_2",
"record Rec {foo: Number, bar: Number, bar2: Number}; let a = {foo: 1, bar: 2, bar2: 3}; match (a) { { foo } => void, _ => void }",
Warnings.NonClosedRecordPattern("bar, bar2"),
);
});

0 comments on commit 4a929fc

Please sign in to comment.