diff --git a/CHANGELOG.md b/CHANGELOG.md index ce1bbb9338..2a3de8b852 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ - More autocomplete improvements involving modules and module types. https://github.com/rescript-lang/rescript/pull/7795 - Autocomplete `@react.componentWithProps` attribute. https://github.com/rescript-lang/rescript/pull/7812 - Add some missing iframe attributes to `domProps`. https://github.com/rescript-lang/rescript/pull/7813 +- Polish error message for inline record escaping scope. https://github.com/rescript-lang/rescript/pull/7808 #### :house: Internal diff --git a/compiler/ml/typecore.ml b/compiler/ml/typecore.ml index ebcd7bb210..90522f13d2 100644 --- a/compiler/ml/typecore.ml +++ b/compiler/ml/typecore.ml @@ -4598,8 +4598,14 @@ let report_error env loc ppf error = "@[Exception patterns must be at the top level of a match case.@]" | Inlined_record_escape -> fprintf ppf - "@[This form is not allowed as the type of the inlined record could \ - escape.@]" + "@[This use of an inlined record is not allowed: its anonymous type \ + would escape its constructor scope.@,\ + @,\ + Possible solutions: @,\ + - Destructure the fields you're interested in from the inline record@,\ + - Change the underlying type to use a defined record as payload instead \ + of an inline record. That will let you use the payload without \ + destructuring it first" | Inlined_record_expected -> fprintf ppf "@[This constructor expects an inlined record argument.@]" | Invalid_extension_constructor_payload -> diff --git a/tests/build_tests/super_errors/expected/inline_record_escape.res.expected b/tests/build_tests/super_errors/expected/inline_record_escape.res.expected new file mode 100644 index 0000000000..7425e757cd --- /dev/null +++ b/tests/build_tests/super_errors/expected/inline_record_escape.res.expected @@ -0,0 +1,14 @@ + + We've found a bug for you! + /.../fixtures/inline_record_escape.res:5:15 + + 3 │ let g = (v: x) => + 4 │ switch v { + 5 │ | One(r) => r + 6 │ } + 7 │ + + This use of an inlined record is not allowed: its anonymous type would escape its constructor scope. + Possible solutions: + - Destructure the fields you're interested in from the inline record + - Change the underlying type to use a defined record as payload instead of an inline record. That will let you use the payload without destructuring it first \ No newline at end of file diff --git a/tests/build_tests/super_errors/fixtures/inline_record_escape.res b/tests/build_tests/super_errors/fixtures/inline_record_escape.res new file mode 100644 index 0000000000..26c5e1db3e --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/inline_record_escape.res @@ -0,0 +1,6 @@ +type x = One({test: bool}) + +let g = (v: x) => + switch v { + | One(r) => r + }