Skip to content

Commit 183d982

Browse files
authored
Try to improve error message about inline record escaping scope (#7808)
* try to improve error message about inline record escaping scope * changelog
1 parent ea569cd commit 183d982

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
- More autocomplete improvements involving modules and module types. https://github.com/rescript-lang/rescript/pull/7795
4141
- Autocomplete `@react.componentWithProps` attribute. https://github.com/rescript-lang/rescript/pull/7812
4242
- Add some missing iframe attributes to `domProps`. https://github.com/rescript-lang/rescript/pull/7813
43+
- Polish error message for inline record escaping scope. https://github.com/rescript-lang/rescript/pull/7808
4344

4445
#### :house: Internal
4546

compiler/ml/typecore.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4598,8 +4598,14 @@ let report_error env loc ppf error =
45984598
"@[Exception patterns must be at the top level of a match case.@]"
45994599
| Inlined_record_escape ->
46004600
fprintf ppf
4601-
"@[This form is not allowed as the type of the inlined record could \
4602-
escape.@]"
4601+
"@[This use of an inlined record is not allowed: its anonymous type \
4602+
would escape its constructor scope.@,\
4603+
@,\
4604+
Possible solutions: @,\
4605+
- Destructure the fields you're interested in from the inline record@,\
4606+
- Change the underlying type to use a defined record as payload instead \
4607+
of an inline record. That will let you use the payload without \
4608+
destructuring it first"
46034609
| Inlined_record_expected ->
46044610
fprintf ppf "@[This constructor expects an inlined record argument.@]"
46054611
| Invalid_extension_constructor_payload ->
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/inline_record_escape.res:5:15
4+
5+
3 │ let g = (v: x) =>
6+
4 │ switch v {
7+
5 │ | One(r) => r
8+
6 │ }
9+
7 │
10+
11+
This use of an inlined record is not allowed: its anonymous type would escape its constructor scope.
12+
Possible solutions:
13+
- Destructure the fields you're interested in from the inline record
14+
- 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
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type x = One({test: bool})
2+
3+
let g = (v: x) =>
4+
switch v {
5+
| One(r) => r
6+
}

0 commit comments

Comments
 (0)