-
Notifications
You must be signed in to change notification settings - Fork 469
Improve various error messages #7500
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
Conversation
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/array_literal_passed_to_tuple.res[0m:[2m5:17-34[0m | ||
|
||
3 [2m│[0m } | ||
4 [2m│[0m | ||
[1;31m5[0m [2m│[0m let x = doStuff([1;31m["hello", "world"][0m) | ||
6 [2m│[0m | ||
|
||
This has type: [1;31marray<'a>[0m | ||
But it's expected to have type: [1;33m(string, string)[0m | ||
|
||
- Fix this by passing a tuple instead of an array, like: [1;33m("hello", "world") | ||
[0m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the user wrote an actual array literal, we can suggest the exact code for turning it into a tuple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome!
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/array_var_passed_to_tuple.res[0m:[2m7:17-18[0m | ||
|
||
5 [2m│[0m let xx = ["hello", "world"] | ||
6 [2m│[0m | ||
[1;31m7[0m [2m│[0m let x = doStuff([1;31mxx[0m) | ||
8 [2m│[0m | ||
|
||
This has type: [1;31marray<string>[0m | ||
But this function argument is expecting: [1;33m(string, string)[0m | ||
|
||
- Fix this by passing a tuple instead of an array[1;33m[0m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When it's not an actual array literal, we just say that you need to pass a tuple instead.
5163b5f
to
131c0ed
Compare
You're passing a [1;31mReScript object[0m where a [1;33mrecord[0m is expected. Objects are written with quoted keys, and records with unquoted keys. | ||
|
||
Possible solutions: | ||
- Rewrite the object to a record, like: [1;33m{one: true} | ||
[0m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another example of how we can suggest an actual and correct rewrite here, since we now have the relevant expression to look at.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is great too! We could also do the same thing for mismatch of objects vs dicts now that we have dict literals, they could become quite common for configs.
rescript
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/darwin-arm64
@rescript/win32-x64
@rescript/linux-x64
commit: |
@@ -41,6 +69,7 @@ let process_file sourcefile ?kind ppf = | |||
properly | |||
*) | |||
setup_outcome_printer (); | |||
Error_message_utils_support.setup (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think process_file
is the appropriate place to run this, but maybe there's a better place, idk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work really @zth. We could also do the same thing for dicts now that we have dict literals that are kinda close to objects syntactically.
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/array_literal_passed_to_tuple.res[0m:[2m5:17-34[0m | ||
|
||
3 [2m│[0m } | ||
4 [2m│[0m | ||
[1;31m5[0m [2m│[0m let x = doStuff([1;31m["hello", "world"][0m) | ||
6 [2m│[0m | ||
|
||
This has type: [1;31marray<'a>[0m | ||
But it's expected to have type: [1;33m(string, string)[0m | ||
|
||
- Fix this by passing a tuple instead of an array, like: [1;33m("hello", "world") | ||
[0m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome!
You need to unwrap this option to its underlying value first, then turn that value into a JSX element. | ||
For [1;33mNone[0m, you can use [1;33mReact.null[0m to output nothing into JSX. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is nice because not obvious for newcomers!
You're passing a [1;31mReScript object[0m where a [1;33mrecord[0m is expected. Objects are written with quoted keys, and records with unquoted keys. | ||
|
||
Possible solutions: | ||
- Rewrite the object to a record, like: [1;33m{one: true} | ||
[0m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is great too! We could also do the same thing for mismatch of objects vs dicts now that we have dict literals, they could become quite common for configs.
Oh, great idea. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome stuff!
tests/build_tests/super_errors/expected/math_operator_float.res.expected
Outdated
Show resolved
Hide resolved
@tsnobip what error messages would you add for dicts? |
@zth Something like this when an object literal is provided but it should actually be a dict:
|
The rewrite part is harder with dict since we need to make sure that they'd be compatible. But I guess some variant of it could be done. Might do it in a follow up though. |
5c85e04
to
2f2dcb7
Compare
This explores how we can re-parse the relevant parts of the source where the error is, to give the viewer more concrete error messages (and suggestions for fixes) that we can't derive just from the type errors we see. It also improves a bunch of specific error messages: