-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error messages for pattern matching mismatches for options/co…
…ncrete values (#7035) * improve error messages for pattern matching mismatches for options/concrete values * changelog
- Loading branch information
Showing
9 changed files
with
73 additions
and
4 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
15 changes: 15 additions & 0 deletions
15
..._tests/super_errors/expected/pattern_matching_on_option_but_value_not_option.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,15 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/pattern_matching_on_option_but_value_not_option.res[0m:[2m4:3-9[0m | ||
|
||
2 [2m│[0m | ||
3 [2m│[0m switch x { | ||
[1;31m4[0m [2m│[0m | [1;31mSome(1)[0m => () | ||
5 [2m│[0m } | ||
6 [2m│[0m | ||
|
||
This pattern matches values of type [1;31moption<'a>[0m | ||
but a pattern was expected which matches values of type [1;33mint[0m | ||
|
||
You're expecting the value you're pattern matching on to be an [1;33moption[0m, but the value is actually not an option. | ||
Change your pattern match to work on the concrete value (remove [1;31mSome(_)[0m or [1;31mNone[0m from the pattern) to make it work. |
15 changes: 15 additions & 0 deletions
15
...mp/build_tests/super_errors/expected/pattern_matching_on_value_but_is_option.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,15 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/pattern_matching_on_value_but_is_option.res[0m:[2m4:3[0m | ||
|
||
2 [2m│[0m | ||
3 [2m│[0m switch x { | ||
[1;31m4[0m [2m│[0m | [1;31m1[0m => () | ||
5 [2m│[0m } | ||
6 [2m│[0m | ||
|
||
This pattern matches values of type [1;31mint[0m | ||
but a pattern was expected which matches values of type [1;33moption<int>[0m | ||
|
||
The value you're pattern matching on here is wrapped in an [1;33moption[0m, but you're trying to match on the actual value. | ||
Wrap the highlighted pattern in [1;33mSome()[0m to make it work. |
5 changes: 5 additions & 0 deletions
5
jscomp/build_tests/super_errors/fixtures/pattern_matching_on_option_but_value_not_option.res
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,5 @@ | ||
let x = 1 | ||
|
||
switch x { | ||
| Some(1) => () | ||
} |
5 changes: 5 additions & 0 deletions
5
jscomp/build_tests/super_errors/fixtures/pattern_matching_on_value_but_is_option.res
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,5 @@ | ||
let x = Some(1) | ||
|
||
switch x { | ||
| 1 => () | ||
} |
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