Skip to content

Improve error message for missing props. #5674

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 1 commit into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions jscomp/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2168,7 +2168,10 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
check_duplicates loc env lbl_exp_list;
let label_descriptions, representation = match lbl_exp_list, repr_opt with
| (_, { lbl_all = label_descriptions; lbl_repres = representation}, _) :: _, _ -> label_descriptions, representation
| [], Some (Record_optional_labels optional_labels as representation) when lid_sexp_list = [] ->
| [], Some (representation) when lid_sexp_list = [] ->
let optional_labels = match representation with
| Record_optional_labels optional_labels -> optional_labels
| _ -> [] in
let filter_missing (ld : Types.label_declaration) =
let name = Ident.name ld.ld_id in
if List.mem name optional_labels then
Expand Down Expand Up @@ -3663,7 +3666,7 @@ let report_error env ppf = function
| Labels_missing labels ->
let print_labels ppf =
List.iter (fun lbl -> fprintf ppf "@ %s" ( lbl)) in
fprintf ppf "@[<hov>Some required record fields are missing:%a@]"
fprintf ppf "@[<hov>Some required record fields are missing:%a. If this is a component, add the missing props.@]"
print_labels labels
| Label_not_mutable lid ->
fprintf ppf "The record field %a is not mutable" longident lid
Expand Down
7 changes: 5 additions & 2 deletions lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41117,7 +41117,10 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
check_duplicates loc env lbl_exp_list;
let label_descriptions, representation = match lbl_exp_list, repr_opt with
| (_, { lbl_all = label_descriptions; lbl_repres = representation}, _) :: _, _ -> label_descriptions, representation
| [], Some (Record_optional_labels optional_labels as representation) when lid_sexp_list = [] ->
| [], Some (representation) when lid_sexp_list = [] ->
let optional_labels = match representation with
| Record_optional_labels optional_labels -> optional_labels
| _ -> [] in
let filter_missing (ld : Types.label_declaration) =
let name = Ident.name ld.ld_id in
if List.mem name optional_labels then
Expand Down Expand Up @@ -42612,7 +42615,7 @@ let report_error env ppf = function
| Labels_missing labels ->
let print_labels ppf =
List.iter (fun lbl -> fprintf ppf "@ %s" ( lbl)) in
fprintf ppf "@[<hov>Some required record fields are missing:%a@]"
fprintf ppf "@[<hov>Some required record fields are missing:%a. If this is a component, add the missing props.@]"
print_labels labels
| Label_not_mutable lid ->
fprintf ppf "The record field %a is not mutable" longident lid
Expand Down
7 changes: 5 additions & 2 deletions lib/4.06.1/unstable/js_playground_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41117,7 +41117,10 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
check_duplicates loc env lbl_exp_list;
let label_descriptions, representation = match lbl_exp_list, repr_opt with
| (_, { lbl_all = label_descriptions; lbl_repres = representation}, _) :: _, _ -> label_descriptions, representation
| [], Some (Record_optional_labels optional_labels as representation) when lid_sexp_list = [] ->
| [], Some (representation) when lid_sexp_list = [] ->
let optional_labels = match representation with
| Record_optional_labels optional_labels -> optional_labels
| _ -> [] in
let filter_missing (ld : Types.label_declaration) =
let name = Ident.name ld.ld_id in
if List.mem name optional_labels then
Expand Down Expand Up @@ -42612,7 +42615,7 @@ let report_error env ppf = function
| Labels_missing labels ->
let print_labels ppf =
List.iter (fun lbl -> fprintf ppf "@ %s" ( lbl)) in
fprintf ppf "@[<hov>Some required record fields are missing:%a@]"
fprintf ppf "@[<hov>Some required record fields are missing:%a. If this is a component, add the missing props.@]"
print_labels labels
| Label_not_mutable lid ->
fprintf ppf "The record field %a is not mutable" longident lid
Expand Down
7 changes: 5 additions & 2 deletions lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -217504,7 +217504,10 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
check_duplicates loc env lbl_exp_list;
let label_descriptions, representation = match lbl_exp_list, repr_opt with
| (_, { lbl_all = label_descriptions; lbl_repres = representation}, _) :: _, _ -> label_descriptions, representation
| [], Some (Record_optional_labels optional_labels as representation) when lid_sexp_list = [] ->
| [], Some (representation) when lid_sexp_list = [] ->
let optional_labels = match representation with
| Record_optional_labels optional_labels -> optional_labels
| _ -> [] in
let filter_missing (ld : Types.label_declaration) =
let name = Ident.name ld.ld_id in
if List.mem name optional_labels then
Expand Down Expand Up @@ -218999,7 +219002,7 @@ let report_error env ppf = function
| Labels_missing labels ->
let print_labels ppf =
List.iter (fun lbl -> fprintf ppf "@ %s" ( lbl)) in
fprintf ppf "@[<hov>Some required record fields are missing:%a@]"
fprintf ppf "@[<hov>Some required record fields are missing:%a. If this is a component, add the missing props.@]"
print_labels labels
| Label_not_mutable lid ->
fprintf ppf "The record field %a is not mutable" longident lid
Expand Down