Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions compiler/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type x = One({test: bool})

let g = (v: x) =>
switch v {
| One(r) => r
}
Loading