Skip to content

Commit 4a929fc

Browse files
feat(compiler): Improve warning when omitting fields in record pattern (#2079)
Co-authored-by: Oscar Spencer <oscar.spen@gmail.com>
1 parent 7eadfb0 commit 4a929fc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

compiler/src/utils/warnings.re

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ let message =
126126
msg,
127127
)
128128
| NonClosedRecordPattern(s) =>
129-
"the following fields are missing from the record pattern: " ++ s
129+
"the following fields are missing from the record pattern: "
130+
++ s
131+
++ "\nUse `_` to ignore unused fields."
130132
| FuncWasmUnsafe(func, f, m) =>
131133
"it looks like you are using "
132134
++ func

compiler/test/suites/records.re

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ describe("records", ({test, testSkip}) => {
230230
"record Rec {foo: Number, bar: Number}; let a = {foo: 1, bar: 2}; let b = {...a, foo: 2, bar: 3}",
231231
Warnings.UselessRecordSpread,
232232
);
233-
234233
assertWarning(
235234
"disambiguation_1",
236235
{|
@@ -256,4 +255,15 @@ describe("records", ({test, testSkip}) => {
256255
(x: B) => x.field
257256
|},
258257
);
258+
// well_formedness field omission warning
259+
assertWarning(
260+
"record_field_omit_1",
261+
"record Rec {foo: Number, bar: Number}; let a = {foo: 1, bar: 2}; match (a) { { foo } => void, _ => void }",
262+
Warnings.NonClosedRecordPattern("bar"),
263+
);
264+
assertWarning(
265+
"record_field_omit_2",
266+
"record Rec {foo: Number, bar: Number, bar2: Number}; let a = {foo: 1, bar: 2, bar2: 3}; match (a) { { foo } => void, _ => void }",
267+
Warnings.NonClosedRecordPattern("bar, bar2"),
268+
);
259269
});

0 commit comments

Comments
 (0)