Skip to content

Commit 17e98e9

Browse files
committed
Print all missing labels in error message for records, not just one.
1 parent 2d06f07 commit 17e98e9

File tree

6 files changed

+44
-40
lines changed

6 files changed

+44
-40
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
- Fix issue where the printer would omit attributes for `->` and `|>` https://github.com/rescript-lang/syntax/pull/629
1919
- Fix printing of optional fields in records https://github.com/rescript-lang/rescript-compiler/issues/5654
2020

21+
#### :nail_care: Polish
22+
23+
- Print all missing labels in error message for records, not just one.
24+
2125
# 10.1.0-alpha.1
2226

2327
#### :boom: Breaking Change

jscomp/ml/typecore.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type error =
3535
| Apply_non_function of type_expr
3636
| Apply_wrong_label of arg_label * type_expr
3737
| Label_multiply_defined of string
38-
| Label_missing of string list
38+
| Labels_missing of string list
3939
| Label_not_mutable of Longident.t
4040
| Wrong_name of string * type_expr * string * Path.t * string * string list
4141
| Name_type_mismatch of
@@ -2167,7 +2167,8 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
21672167
unify_exp_types loc env ty_record (instance env ty_expected);
21682168
check_duplicates loc env lbl_exp_list;
21692169
let (_, { lbl_all = label_descriptions; lbl_repres = representation}, _) = List.hd lbl_exp_list in
2170-
let label_definitions =
2170+
let labels_missing = ref [] in
2171+
let label_definitions =
21712172
let matching_label lbl =
21722173
List.find
21732174
(fun (_, lbl',_) -> lbl'.lbl_pos = lbl.lbl_pos)
@@ -2179,13 +2180,12 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
21792180
| (lid, _lbl, lbl_exp) ->
21802181
Overridden (lid, lbl_exp)
21812182
| exception Not_found ->
2182-
if label_is_optional lbl then
2183-
Overridden ({loc ; txt = Lident lbl.lbl_name},
2184-
option_none lbl.lbl_arg loc)
2185-
else
2186-
raise(Error(loc, env, Label_missing [lbl.lbl_name])))
2183+
if not (label_is_optional lbl) then labels_missing := lbl.lbl_name :: !labels_missing;
2184+
Overridden ({loc ; txt = Lident lbl.lbl_name}, option_none lbl.lbl_arg loc))
21872185
label_descriptions
21882186
in
2187+
if !labels_missing <> [] then
2188+
raise(Error(loc, env, Labels_missing (List.rev !labels_missing)));
21892189
let fields =
21902190
Array.map2 (fun descr def -> descr, def)
21912191
label_descriptions label_definitions
@@ -3643,10 +3643,10 @@ let report_error env ppf = function
36433643
type_expr ty print_label l
36443644
| Label_multiply_defined s ->
36453645
fprintf ppf "The record field label %s is defined several times" s
3646-
| Label_missing labels ->
3646+
| Labels_missing labels ->
36473647
let print_labels ppf =
36483648
List.iter (fun lbl -> fprintf ppf "@ %s" ( lbl)) in
3649-
fprintf ppf "@[<hov>Some record fields are undefined:%a@]"
3649+
fprintf ppf "@[<hov>Some required record fields are missing:%a@]"
36503650
print_labels labels
36513651
| Label_not_mutable lid ->
36523652
fprintf ppf "The record field %a is not mutable" longident lid

jscomp/ml/typecore.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type error =
7272
| Apply_non_function of type_expr
7373
| Apply_wrong_label of arg_label * type_expr
7474
| Label_multiply_defined of string
75-
| Label_missing of string list
75+
| Labels_missing of string list
7676
| Label_not_mutable of Longident.t
7777
| Wrong_name of string * type_expr * string * Path.t * string * string list
7878
| Name_type_mismatch of

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38879,7 +38879,7 @@ type error =
3887938879
| Apply_non_function of type_expr
3888038880
| Apply_wrong_label of arg_label * type_expr
3888138881
| Label_multiply_defined of string
38882-
| Label_missing of string list
38882+
| Labels_missing of string list
3888338883
| Label_not_mutable of Longident.t
3888438884
| Wrong_name of string * type_expr * string * Path.t * string * string list
3888538885
| Name_type_mismatch of
@@ -38984,7 +38984,7 @@ type error =
3898438984
| Apply_non_function of type_expr
3898538985
| Apply_wrong_label of arg_label * type_expr
3898638986
| Label_multiply_defined of string
38987-
| Label_missing of string list
38987+
| Labels_missing of string list
3898838988
| Label_not_mutable of Longident.t
3898938989
| Wrong_name of string * type_expr * string * Path.t * string * string list
3899038990
| Name_type_mismatch of
@@ -41116,7 +41116,8 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
4111641116
unify_exp_types loc env ty_record (instance env ty_expected);
4111741117
check_duplicates loc env lbl_exp_list;
4111841118
let (_, { lbl_all = label_descriptions; lbl_repres = representation}, _) = List.hd lbl_exp_list in
41119-
let label_definitions =
41119+
let labels_missing = ref [] in
41120+
let label_definitions =
4112041121
let matching_label lbl =
4112141122
List.find
4112241123
(fun (_, lbl',_) -> lbl'.lbl_pos = lbl.lbl_pos)
@@ -41128,13 +41129,12 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
4112841129
| (lid, _lbl, lbl_exp) ->
4112941130
Overridden (lid, lbl_exp)
4113041131
| exception Not_found ->
41131-
if label_is_optional lbl then
41132-
Overridden ({loc ; txt = Lident lbl.lbl_name},
41133-
option_none lbl.lbl_arg loc)
41134-
else
41135-
raise(Error(loc, env, Label_missing [lbl.lbl_name])))
41132+
if not (label_is_optional lbl) then labels_missing := lbl.lbl_name :: !labels_missing;
41133+
Overridden ({loc ; txt = Lident lbl.lbl_name}, option_none lbl.lbl_arg loc))
4113641134
label_descriptions
4113741135
in
41136+
if !labels_missing <> [] then
41137+
raise(Error(loc, env, Labels_missing (List.rev !labels_missing)));
4113841138
let fields =
4113941139
Array.map2 (fun descr def -> descr, def)
4114041140
label_descriptions label_definitions
@@ -42592,10 +42592,10 @@ let report_error env ppf = function
4259242592
type_expr ty print_label l
4259342593
| Label_multiply_defined s ->
4259442594
fprintf ppf "The record field label %s is defined several times" s
42595-
| Label_missing labels ->
42595+
| Labels_missing labels ->
4259642596
let print_labels ppf =
4259742597
List.iter (fun lbl -> fprintf ppf "@ %s" ( lbl)) in
42598-
fprintf ppf "@[<hov>Some record fields are undefined:%a@]"
42598+
fprintf ppf "@[<hov>Some required record fields are missing:%a@]"
4259942599
print_labels labels
4260042600
| Label_not_mutable lid ->
4260142601
fprintf ppf "The record field %a is not mutable" longident lid

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38879,7 +38879,7 @@ type error =
3887938879
| Apply_non_function of type_expr
3888038880
| Apply_wrong_label of arg_label * type_expr
3888138881
| Label_multiply_defined of string
38882-
| Label_missing of string list
38882+
| Labels_missing of string list
3888338883
| Label_not_mutable of Longident.t
3888438884
| Wrong_name of string * type_expr * string * Path.t * string * string list
3888538885
| Name_type_mismatch of
@@ -38984,7 +38984,7 @@ type error =
3898438984
| Apply_non_function of type_expr
3898538985
| Apply_wrong_label of arg_label * type_expr
3898638986
| Label_multiply_defined of string
38987-
| Label_missing of string list
38987+
| Labels_missing of string list
3898838988
| Label_not_mutable of Longident.t
3898938989
| Wrong_name of string * type_expr * string * Path.t * string * string list
3899038990
| Name_type_mismatch of
@@ -41116,7 +41116,8 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
4111641116
unify_exp_types loc env ty_record (instance env ty_expected);
4111741117
check_duplicates loc env lbl_exp_list;
4111841118
let (_, { lbl_all = label_descriptions; lbl_repres = representation}, _) = List.hd lbl_exp_list in
41119-
let label_definitions =
41119+
let labels_missing = ref [] in
41120+
let label_definitions =
4112041121
let matching_label lbl =
4112141122
List.find
4112241123
(fun (_, lbl',_) -> lbl'.lbl_pos = lbl.lbl_pos)
@@ -41128,13 +41129,12 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
4112841129
| (lid, _lbl, lbl_exp) ->
4112941130
Overridden (lid, lbl_exp)
4113041131
| exception Not_found ->
41131-
if label_is_optional lbl then
41132-
Overridden ({loc ; txt = Lident lbl.lbl_name},
41133-
option_none lbl.lbl_arg loc)
41134-
else
41135-
raise(Error(loc, env, Label_missing [lbl.lbl_name])))
41132+
if not (label_is_optional lbl) then labels_missing := lbl.lbl_name :: !labels_missing;
41133+
Overridden ({loc ; txt = Lident lbl.lbl_name}, option_none lbl.lbl_arg loc))
4113641134
label_descriptions
4113741135
in
41136+
if !labels_missing <> [] then
41137+
raise(Error(loc, env, Labels_missing (List.rev !labels_missing)));
4113841138
let fields =
4113941139
Array.map2 (fun descr def -> descr, def)
4114041140
label_descriptions label_definitions
@@ -42592,10 +42592,10 @@ let report_error env ppf = function
4259242592
type_expr ty print_label l
4259342593
| Label_multiply_defined s ->
4259442594
fprintf ppf "The record field label %s is defined several times" s
42595-
| Label_missing labels ->
42595+
| Labels_missing labels ->
4259642596
let print_labels ppf =
4259742597
List.iter (fun lbl -> fprintf ppf "@ %s" ( lbl)) in
42598-
fprintf ppf "@[<hov>Some record fields are undefined:%a@]"
42598+
fprintf ppf "@[<hov>Some required record fields are missing:%a@]"
4259942599
print_labels labels
4260042600
| Label_not_mutable lid ->
4260142601
fprintf ppf "The record field %a is not mutable" longident lid

lib/4.06.1/whole_compiler.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215266,7 +215266,7 @@ type error =
215266215266
| Apply_non_function of type_expr
215267215267
| Apply_wrong_label of arg_label * type_expr
215268215268
| Label_multiply_defined of string
215269-
| Label_missing of string list
215269+
| Labels_missing of string list
215270215270
| Label_not_mutable of Longident.t
215271215271
| Wrong_name of string * type_expr * string * Path.t * string * string list
215272215272
| Name_type_mismatch of
@@ -215371,7 +215371,7 @@ type error =
215371215371
| Apply_non_function of type_expr
215372215372
| Apply_wrong_label of arg_label * type_expr
215373215373
| Label_multiply_defined of string
215374-
| Label_missing of string list
215374+
| Labels_missing of string list
215375215375
| Label_not_mutable of Longident.t
215376215376
| Wrong_name of string * type_expr * string * Path.t * string * string list
215377215377
| Name_type_mismatch of
@@ -217503,7 +217503,8 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
217503217503
unify_exp_types loc env ty_record (instance env ty_expected);
217504217504
check_duplicates loc env lbl_exp_list;
217505217505
let (_, { lbl_all = label_descriptions; lbl_repres = representation}, _) = List.hd lbl_exp_list in
217506-
let label_definitions =
217506+
let labels_missing = ref [] in
217507+
let label_definitions =
217507217508
let matching_label lbl =
217508217509
List.find
217509217510
(fun (_, lbl',_) -> lbl'.lbl_pos = lbl.lbl_pos)
@@ -217515,13 +217516,12 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
217515217516
| (lid, _lbl, lbl_exp) ->
217516217517
Overridden (lid, lbl_exp)
217517217518
| exception Not_found ->
217518-
if label_is_optional lbl then
217519-
Overridden ({loc ; txt = Lident lbl.lbl_name},
217520-
option_none lbl.lbl_arg loc)
217521-
else
217522-
raise(Error(loc, env, Label_missing [lbl.lbl_name])))
217519+
if not (label_is_optional lbl) then labels_missing := lbl.lbl_name :: !labels_missing;
217520+
Overridden ({loc ; txt = Lident lbl.lbl_name}, option_none lbl.lbl_arg loc))
217523217521
label_descriptions
217524217522
in
217523+
if !labels_missing <> [] then
217524+
raise(Error(loc, env, Labels_missing (List.rev !labels_missing)));
217525217525
let fields =
217526217526
Array.map2 (fun descr def -> descr, def)
217527217527
label_descriptions label_definitions
@@ -218979,10 +218979,10 @@ let report_error env ppf = function
218979218979
type_expr ty print_label l
218980218980
| Label_multiply_defined s ->
218981218981
fprintf ppf "The record field label %s is defined several times" s
218982-
| Label_missing labels ->
218982+
| Labels_missing labels ->
218983218983
let print_labels ppf =
218984218984
List.iter (fun lbl -> fprintf ppf "@ %s" ( lbl)) in
218985-
fprintf ppf "@[<hov>Some record fields are undefined:%a@]"
218985+
fprintf ppf "@[<hov>Some required record fields are missing:%a@]"
218986218986
print_labels labels
218987218987
| Label_not_mutable lid ->
218988218988
fprintf ppf "The record field %a is not mutable" longident lid

0 commit comments

Comments
 (0)