From bb22c459d73735b088695e748ef78c8bc34ec41c Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Tue, 1 Oct 2024 21:00:03 +0200 Subject: [PATCH 1/3] tweak unbound record field error message --- .../expected/unbound_record_field.res.expected | 16 ++++++++++++++++ .../fixtures/unbound_record_field.res | 4 ++++ jscomp/ml/typetexp.ml | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 jscomp/build_tests/super_errors/expected/unbound_record_field.res.expected create mode 100644 jscomp/build_tests/super_errors/fixtures/unbound_record_field.res diff --git a/jscomp/build_tests/super_errors/expected/unbound_record_field.res.expected b/jscomp/build_tests/super_errors/expected/unbound_record_field.res.expected new file mode 100644 index 0000000000..979c7124d3 --- /dev/null +++ b/jscomp/build_tests/super_errors/expected/unbound_record_field.res.expected @@ -0,0 +1,16 @@ + + We've found a bug for you! + /.../fixtures/unbound_record_field.res:3:6-21 + + 1 │ let foo = x => + 2 │ switch x { + 3 │ | {someUnknownField: 123} => () + 4 │ } + 5 │ + + someUnknownField refers to a record field, but the record type it belongs to couldn't be found automatically. + + If it's defined in another module or file, bring it into scope by: + - Prefixing it with said module name: TheModule.someUnknownField + - Or specifying its type: + let theValue: TheModule.theType = {someUnknownField: VALUE} \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/fixtures/unbound_record_field.res b/jscomp/build_tests/super_errors/fixtures/unbound_record_field.res new file mode 100644 index 0000000000..074704bff1 --- /dev/null +++ b/jscomp/build_tests/super_errors/fixtures/unbound_record_field.res @@ -0,0 +1,4 @@ +let foo = x => + switch x { + | {someUnknownField: 123} => () + } diff --git a/jscomp/ml/typetexp.ml b/jscomp/ml/typetexp.ml index def4427a3b..fe69beb1a2 100644 --- a/jscomp/ml/typetexp.ml +++ b/jscomp/ml/typetexp.ml @@ -910,7 +910,7 @@ let report_error env ppf = function | Unbound_label lid -> (* modified *) Format.fprintf ppf "@[\ - @{The record field %a can't be found.@}@,@,\ + @{%a@} refers to a record field, but the record type it belongs to couldn't be found automatically.@,@,\ If it's defined in another module or file, bring it into scope by:@,\ @[- Prefixing it with said module name:@ @{TheModule.%a@}@]@,\ @[- Or specifying its type:@ @{let theValue: TheModule.theType = {%a: VALUE}@}@]\ From d4c0ee0b1f86d342d73b6a21991dc2b462c58b4b Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Wed, 2 Oct 2024 15:17:11 +0200 Subject: [PATCH 2/3] update message --- .../super_errors/expected/unbound_record_field.res.expected | 2 +- jscomp/ml/typetexp.ml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jscomp/build_tests/super_errors/expected/unbound_record_field.res.expected b/jscomp/build_tests/super_errors/expected/unbound_record_field.res.expected index 979c7124d3..100edf3616 100644 --- a/jscomp/build_tests/super_errors/expected/unbound_record_field.res.expected +++ b/jscomp/build_tests/super_errors/expected/unbound_record_field.res.expected @@ -8,7 +8,7 @@ 4 │ } 5 │ - someUnknownField refers to a record field, but the record type it belongs to couldn't be found automatically. + someUnknownField refers to a record field, but no corresponding record type is in scope. If it's defined in another module or file, bring it into scope by: - Prefixing it with said module name: TheModule.someUnknownField diff --git a/jscomp/ml/typetexp.ml b/jscomp/ml/typetexp.ml index fe69beb1a2..4ffd72b0e1 100644 --- a/jscomp/ml/typetexp.ml +++ b/jscomp/ml/typetexp.ml @@ -910,7 +910,7 @@ let report_error env ppf = function | Unbound_label lid -> (* modified *) Format.fprintf ppf "@[\ - @{%a@} refers to a record field, but the record type it belongs to couldn't be found automatically.@,@,\ + @{%a@} refers to a record field, but no corresponding record type is in scope.@,@,\ If it's defined in another module or file, bring it into scope by:@,\ @[- Prefixing it with said module name:@ @{TheModule.%a@}@]@,\ @[- Or specifying its type:@ @{let theValue: TheModule.theType = {%a: VALUE}@}@]\ From 2f6c91ff1a26a5f68dbe32aaa41558ce3cf7e004 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Wed, 2 Oct 2024 16:05:33 +0200 Subject: [PATCH 3/3] fix message --- .../super_errors/expected/unbound_record_field.res.expected | 4 ++-- jscomp/ml/typetexp.ml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jscomp/build_tests/super_errors/expected/unbound_record_field.res.expected b/jscomp/build_tests/super_errors/expected/unbound_record_field.res.expected index 100edf3616..29ea442502 100644 --- a/jscomp/build_tests/super_errors/expected/unbound_record_field.res.expected +++ b/jscomp/build_tests/super_errors/expected/unbound_record_field.res.expected @@ -11,6 +11,6 @@ someUnknownField refers to a record field, but no corresponding record type is in scope. If it's defined in another module or file, bring it into scope by: - - Prefixing it with said module name: TheModule.someUnknownField - - Or specifying its type: + - Prefixing the field name with the module name: TheModule.someUnknownField + - Or specifying the record type explicitly: let theValue: TheModule.theType = {someUnknownField: VALUE} \ No newline at end of file diff --git a/jscomp/ml/typetexp.ml b/jscomp/ml/typetexp.ml index 4ffd72b0e1..aa8cdf6d5d 100644 --- a/jscomp/ml/typetexp.ml +++ b/jscomp/ml/typetexp.ml @@ -912,8 +912,8 @@ let report_error env ppf = function Format.fprintf ppf "@[\ @{%a@} refers to a record field, but no corresponding record type is in scope.@,@,\ If it's defined in another module or file, bring it into scope by:@,\ - @[- Prefixing it with said module name:@ @{TheModule.%a@}@]@,\ - @[- Or specifying its type:@ @{let theValue: TheModule.theType = {%a: VALUE}@}@]\ + @[- Prefixing the field name with the module name:@ @{TheModule.%a@}@]@,\ + @[- Or specifying the record type explicitly:@ @{let theValue: TheModule.theType = {%a: VALUE}@}@]\ @]" Printtyp.longident lid Printtyp.longident lid