-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Error messages: Improve "Somewhere wanted" messages (#6410)
* first batch of changes trying to improve the Somewhere wanted error messages * tweaks * add more fixtures * remove redundant text * add specialized errors for array items and setting record fields * tweak set record field message * hint about tuple in array message * move message handling to own file * cleanup * cleanup * cleanup * cleanup * changelog * add example of tuple to error message
- Loading branch information
Showing
48 changed files
with
558 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
jscomp/build_tests/super_errors/expected/array_item_type_mismatch.res.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/array_item_type_mismatch.res[0m:[2m1:16-22[0m | ||
|
||
[1;31m1[0m [2m│[0m let x = [1, 2, [1;31m"hello"[0m] | ||
2 [2m│[0m | ||
|
||
This array item has type: [1;31mstring[0m | ||
But this array is expected to have items of type: [1;33mint[0m | ||
|
||
Arrays can only contain items of the same type. | ||
|
||
Possible solutions: | ||
- Convert all values in the array to the same type. | ||
- Use a tuple, if your array is of fixed length. Tuples can mix types freely, and compiles to a JavaScript array. Example of a tuple: `let myTuple = (10, "hello", 15.5, true) | ||
|
||
You can convert [1;33mstring[0m to [1;33mint[0m with [1;33mBelt.Int.fromString[0m. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
jscomp/build_tests/super_errors/expected/comparison_operator.res.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/comparison_operator.res[0m:[2m3:17[0m | ||
|
||
1 [2m│[0m let f = Some(0) | ||
2 [2m│[0m | ||
[1;31m3[0m [2m│[0m let x = 100 === [1;31mf[0m | ||
4 [2m│[0m | ||
|
||
This has type: [1;31moption<int>[0m | ||
But it's being compared to something of type: [1;33mint[0m | ||
|
||
You can only compare things of the same type. |
13 changes: 13 additions & 0 deletions
13
jscomp/build_tests/super_errors/expected/function_argument_mismatch.res.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/function_argument_mismatch.res[0m:[2m3:28-30[0m | ||
|
||
1 [2m│[0m let makeName = (s, i) => s ++ i | ||
2 [2m│[0m | ||
[1;31m3[0m [2m│[0m let name = makeName("123", [1;31m123[0m) | ||
4 [2m│[0m | ||
|
||
This has type: [1;31mint[0m | ||
But this function argument is expecting: [1;33mstring[0m | ||
|
||
You can convert [1;33mint[0m to [1;33mstring[0m with [1;33mBelt.Int.toString[0m. |
12 changes: 12 additions & 0 deletions
12
jscomp/build_tests/super_errors/expected/function_call_mismatch.res.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/function_call_mismatch.res[0m:[2m6:3-10[0m | ||
|
||
4 [2m│[0m | ||
5 [2m│[0m let cloneInTemp = (temp: string): string => { | ||
[1;31m6[0m [2m│[0m [1;31mcd(temp)[0m | ||
7 [2m│[0m exec("git clone [email protected]:myorg/myrepo.git") | ||
8 [2m│[0m } | ||
|
||
This function call returns: [1;31mstring[0m | ||
But it's expected to return: [1;33munit[0m |
12 changes: 12 additions & 0 deletions
12
jscomp/build_tests/super_errors/expected/function_return_mismatch.res.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/function_return_mismatch.res[0m:[2m9:3-5[0m | ||
|
||
7 [2m│[0m | ||
8 [2m│[0m let x = fnExpectingCleanup(() => { | ||
[1;31m9[0m [2m│[0m [1;31m123[0m | ||
10 [2m│[0m }) | ||
11 [2m│[0m | ||
|
||
This has type: [1;31mint[0m | ||
But it's expected to have type: [1;33mcleanup[0m [2m(defined as[0m [1;33munit => unit[0m[2m)[0m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
jscomp/build_tests/super_errors/expected/if_branch_mismatch.res.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/if_branch_mismatch.res[0m:[2m4:3-5[0m | ||
|
||
2 [2m│[0m "123" | ||
3 [2m│[0m } else { | ||
[1;31m4[0m [2m│[0m [1;31m123[0m | ||
5 [2m│[0m } | ||
6 [2m│[0m | ||
|
||
This has type: [1;31mint[0m | ||
But this [1;33mif[0m statement is expected to return: [1;33mstring[0m | ||
|
||
[1;33mif[0m expressions must return the same type in all branches ([1;33mif[0m, [1;33melse if[0m, [1;33melse[0m). | ||
|
||
You can convert [1;33mint[0m to [1;33mstring[0m with [1;33mBelt.Int.toString[0m. |
12 changes: 12 additions & 0 deletions
12
jscomp/build_tests/super_errors/expected/if_condition_mismatch.res.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/if_condition_mismatch.res[0m:[2m1:12-18[0m | ||
|
||
[1;31m1[0m [2m│[0m let x = if [1;31m"horse"[0m { | ||
2 [2m│[0m () | ||
3 [2m│[0m } | ||
|
||
This has type: [1;31mstring[0m | ||
But [1;33mif[0m conditions must always be of type: [1;33mbool[0m | ||
|
||
To fix this, change the highlighted code so it evaluates to a [1;33mbool[0m. |
20 changes: 20 additions & 0 deletions
20
jscomp/build_tests/super_errors/expected/math_operator_constant.res.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/math_operator_constant.res[0m:[2m3:15-17[0m | ||
|
||
1 [2m│[0m let num = 0 | ||
2 [2m│[0m | ||
[1;31m3[0m [2m│[0m let x = num + [1;31m12.[0m | ||
4 [2m│[0m | ||
|
||
This value has type: [1;31mfloat[0m | ||
But it's being used with the [1;33m+[0m operator, which works on: [1;33mint[0m | ||
|
||
Floats and ints have their own mathematical operators. This means you cannot add a float and an int without converting between the two. | ||
|
||
Possible solutions: | ||
- Ensure all values in this calculation has the type [1;33mint[0m. You can convert between floats and ints via [1;33mBelt.Float.toInt[0m and [1;33mBelt.Int.fromFloat[0m. | ||
- Make [1;33m12.[0m an [1;33mint[0m by removing the dot or explicitly converting to int | ||
|
||
You can convert [1;33mfloat[0m to [1;33mint[0m with [1;33mBelt.Float.toInt[0m. | ||
If this is a literal, try a number without a trailing dot (e.g. [1;33m20[0m). |
20 changes: 20 additions & 0 deletions
20
jscomp/build_tests/super_errors/expected/math_operator_float.res.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/math_operator_float.res[0m:[2m3:9-11[0m | ||
|
||
1 [2m│[0m let num = 0 | ||
2 [2m│[0m | ||
[1;31m3[0m [2m│[0m let x = [1;31mnum[0m +. 12. | ||
4 [2m│[0m | ||
|
||
This has type: [1;31mint[0m | ||
But it's being used with the [1;33m+.[0m operator, which works on: [1;33mfloat[0m | ||
|
||
Floats and ints have their own mathematical operators. This means you cannot add a float and an int without converting between the two. | ||
|
||
Possible solutions: | ||
- Ensure all values in this calculation has the type [1;33mfloat[0m. You can convert between floats and ints via [1;33mBelt.Float.toInt[0m and [1;33mBelt.Int.fromFloat[0m. | ||
- Change the operator to [1;33m+[0m, which works on [1;33mint[0m | ||
|
||
You can convert [1;33mint[0m to [1;33mfloat[0m with [1;33mBelt.Int.toFloat[0m. | ||
If this is a literal, try a number with a trailing dot (e.g. [1;33m20.[0m). |
20 changes: 20 additions & 0 deletions
20
jscomp/build_tests/super_errors/expected/math_operator_int.res.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/math_operator_int.res[0m:[2m3:9-11[0m | ||
|
||
1 [2m│[0m let num = 0. | ||
2 [2m│[0m | ||
[1;31m3[0m [2m│[0m let x = [1;31mnum[0m + 12. | ||
4 [2m│[0m | ||
|
||
This has type: [1;31mfloat[0m | ||
But it's being used with the [1;33m+[0m operator, which works on: [1;33mint[0m | ||
|
||
Floats and ints have their own mathematical operators. This means you cannot add a float and an int without converting between the two. | ||
|
||
Possible solutions: | ||
- Ensure all values in this calculation has the type [1;33mint[0m. You can convert between floats and ints via [1;33mBelt.Float.toInt[0m and [1;33mBelt.Int.fromFloat[0m. | ||
- Change the operator to [1;33m+.[0m, which works on [1;33mfloat[0m | ||
|
||
You can convert [1;33mfloat[0m to [1;33mint[0m with [1;33mBelt.Float.toInt[0m. | ||
If this is a literal, try a number without a trailing dot (e.g. [1;33m20[0m). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
jscomp/build_tests/super_errors/expected/set_record_field_type_match.res.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/set_record_field_type_match.res[0m:[2m11:13-14[0m | ||
|
||
9 [2m│[0m } | ||
10 [2m│[0m | ||
[1;31m11[0m [2m│[0m user.name = [1;31m12[0m | ||
12 [2m│[0m | ||
|
||
You're assigning something to this field that has type: [1;31mint[0m | ||
But this record field is of type: [1;33mstring[0m | ||
|
||
You can convert [1;33mint[0m to [1;33mstring[0m with [1;33mBelt.Int.toString[0m. |
14 changes: 14 additions & 0 deletions
14
jscomp/build_tests/super_errors/expected/switch_different_types.res.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/switch_different_types.res[0m:[2m7:10-23[0m | ||
|
||
5 [2m│[0m switch foo { | ||
6 [2m│[0m | "world" => () | ||
[1;31m7[0m [2m│[0m | _ => [1;31msomeFunction()[0m | ||
8 [2m│[0m } | ||
9 [2m│[0m } | ||
|
||
This has type: [1;31mstring[0m | ||
But this switch is expected to return: [1;33munit[0m | ||
|
||
All branches in a [1;33mswitch[0m must return the same type. To fix this, change your branch to return the expected type. |
14 changes: 14 additions & 0 deletions
14
jscomp/build_tests/super_errors/expected/switch_guard.res.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/switch_guard.res[0m:[2m6:16-22[0m | ||
|
||
4 [2m│[0m let bar = () => { | ||
5 [2m│[0m switch foo { | ||
[1;31m6[0m [2m│[0m | "world" if [1;31m"horse"[0m => () | ||
7 [2m│[0m | _ => someFunction() | ||
8 [2m│[0m } | ||
|
||
This has type: [1;31mstring[0m | ||
But [1;33mif[0m conditions must always be of type: [1;33mbool[0m | ||
|
||
To fix this, change the highlighted code so it evaluates to a [1;33mbool[0m. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.