Skip to content

Commit b584d3f

Browse files
committed
Improve error message for missing props.
Fix an issue where a wrong error (empty record not annotated) was issues when `{}` has type a record without optional fields. Improve error message when mandatory fields are missing, suggesting it could be a component.
1 parent 2ab41fb commit b584d3f

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

jscomp/ml/typecore.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,10 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
21682168
check_duplicates loc env lbl_exp_list;
21692169
let label_descriptions, representation = match lbl_exp_list, repr_opt with
21702170
| (_, { lbl_all = label_descriptions; lbl_repres = representation}, _) :: _, _ -> label_descriptions, representation
2171-
| [], Some (Record_optional_labels optional_labels as representation) when lid_sexp_list = [] ->
2171+
| [], Some (representation) when lid_sexp_list = [] ->
2172+
let optional_labels = match representation with
2173+
| Record_optional_labels optional_labels -> optional_labels
2174+
| _ -> [] in
21722175
let filter_missing (ld : Types.label_declaration) =
21732176
let name = Ident.name ld.ld_id in
21742177
if List.mem name optional_labels then
@@ -3663,7 +3666,7 @@ let report_error env ppf = function
36633666
| Labels_missing labels ->
36643667
let print_labels ppf =
36653668
List.iter (fun lbl -> fprintf ppf "@ %s" ( lbl)) in
3666-
fprintf ppf "@[<hov>Some required record fields are missing:%a@]"
3669+
fprintf ppf "@[<hov>Some required record fields are missing:%a. If this is a component, add the missing props.@]"
36673670
print_labels labels
36683671
| Label_not_mutable lid ->
36693672
fprintf ppf "The record field %a is not mutable" longident lid

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41117,7 +41117,10 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
4111741117
check_duplicates loc env lbl_exp_list;
4111841118
let label_descriptions, representation = match lbl_exp_list, repr_opt with
4111941119
| (_, { lbl_all = label_descriptions; lbl_repres = representation}, _) :: _, _ -> label_descriptions, representation
41120-
| [], Some (Record_optional_labels optional_labels as representation) when lid_sexp_list = [] ->
41120+
| [], Some (representation) when lid_sexp_list = [] ->
41121+
let optional_labels = match representation with
41122+
| Record_optional_labels optional_labels -> optional_labels
41123+
| _ -> [] in
4112141124
let filter_missing (ld : Types.label_declaration) =
4112241125
let name = Ident.name ld.ld_id in
4112341126
if List.mem name optional_labels then
@@ -42612,7 +42615,7 @@ let report_error env ppf = function
4261242615
| Labels_missing labels ->
4261342616
let print_labels ppf =
4261442617
List.iter (fun lbl -> fprintf ppf "@ %s" ( lbl)) in
42615-
fprintf ppf "@[<hov>Some required record fields are missing:%a@]"
42618+
fprintf ppf "@[<hov>Some required record fields are missing:%a. If this is a component, add the missing props.@]"
4261642619
print_labels labels
4261742620
| Label_not_mutable lid ->
4261842621
fprintf ppf "The record field %a is not mutable" longident lid

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41117,7 +41117,10 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
4111741117
check_duplicates loc env lbl_exp_list;
4111841118
let label_descriptions, representation = match lbl_exp_list, repr_opt with
4111941119
| (_, { lbl_all = label_descriptions; lbl_repres = representation}, _) :: _, _ -> label_descriptions, representation
41120-
| [], Some (Record_optional_labels optional_labels as representation) when lid_sexp_list = [] ->
41120+
| [], Some (representation) when lid_sexp_list = [] ->
41121+
let optional_labels = match representation with
41122+
| Record_optional_labels optional_labels -> optional_labels
41123+
| _ -> [] in
4112141124
let filter_missing (ld : Types.label_declaration) =
4112241125
let name = Ident.name ld.ld_id in
4112341126
if List.mem name optional_labels then
@@ -42612,7 +42615,7 @@ let report_error env ppf = function
4261242615
| Labels_missing labels ->
4261342616
let print_labels ppf =
4261442617
List.iter (fun lbl -> fprintf ppf "@ %s" ( lbl)) in
42615-
fprintf ppf "@[<hov>Some required record fields are missing:%a@]"
42618+
fprintf ppf "@[<hov>Some required record fields are missing:%a. If this is a component, add the missing props.@]"
4261642619
print_labels labels
4261742620
| Label_not_mutable lid ->
4261842621
fprintf ppf "The record field %a is not mutable" longident lid

lib/4.06.1/whole_compiler.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217504,7 +217504,10 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
217504217504
check_duplicates loc env lbl_exp_list;
217505217505
let label_descriptions, representation = match lbl_exp_list, repr_opt with
217506217506
| (_, { lbl_all = label_descriptions; lbl_repres = representation}, _) :: _, _ -> label_descriptions, representation
217507-
| [], Some (Record_optional_labels optional_labels as representation) when lid_sexp_list = [] ->
217507+
| [], Some (representation) when lid_sexp_list = [] ->
217508+
let optional_labels = match representation with
217509+
| Record_optional_labels optional_labels -> optional_labels
217510+
| _ -> [] in
217508217511
let filter_missing (ld : Types.label_declaration) =
217509217512
let name = Ident.name ld.ld_id in
217510217513
if List.mem name optional_labels then
@@ -218999,7 +219002,7 @@ let report_error env ppf = function
218999219002
| Labels_missing labels ->
219000219003
let print_labels ppf =
219001219004
List.iter (fun lbl -> fprintf ppf "@ %s" ( lbl)) in
219002-
fprintf ppf "@[<hov>Some required record fields are missing:%a@]"
219005+
fprintf ppf "@[<hov>Some required record fields are missing:%a. If this is a component, add the missing props.@]"
219003219006
print_labels labels
219004219007
| Label_not_mutable lid ->
219005219008
fprintf ppf "The record field %a is not mutable" longident lid

0 commit comments

Comments
 (0)