Repository navigation
Support int range patterns #8894
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| - Int range patterns such as `200 .. 299` are supported in `switch`, and their bounds may mix ints and chars. |
This file contains hidden or 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 hidden or 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
11 changes: 11 additions & 0 deletions
11
tests/build_tests/super_errors/expected/pattern_interval_float.res.expected
This file contains hidden or 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,11 @@ | ||
|
|
||
| [1;31mWe've found a bug for you![0m | ||
| [36m/.../fixtures/pattern_interval_float.res[0m:[2m3:5-14[0m | ||
|
|
||
| 1 [2m│[0m let f = x => | ||
| 2 [2m│[0m switch x { | ||
| [1;31m3[0m [2m│[0m | [1;31m1.0 .. 5.0[0m => "low" | ||
| 4 [2m│[0m | _ => "other" | ||
| 5 [2m│[0m } | ||
|
|
||
| Only int and char intervals are supported in patterns. |
11 changes: 0 additions & 11 deletions
11
tests/build_tests/super_errors/expected/pattern_interval_non_char.res.expected
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
tests/build_tests/super_errors/expected/warning_8_int_range_example.res.expected
This file contains hidden or 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;33mWarning number 8[0m | ||
| [36m/.../fixtures/warning_8_int_range_example.res[0m:[2m3:3-6:3[0m | ||
|
|
||
| 1 [2m│[0m // All non-negative ints are covered, so the example is negative. | ||
| 2 [2m│[0m let f = x => | ||
| [1;33m3[0m [2m│[0m [1;33mswitch x {[0m | ||
| [1;33m4[0m [2m│[0m [1;33m | 0 .. 0x7FFFFFFF => true[0m | ||
| [1;33m5[0m [2m│[0m [1;33m | -10 .. -1 => false[0m | ||
| [1;33m6[0m [2m│[0m [1;33m }[0m | ||
| 7 [2m│[0m | ||
|
|
||
| You forgot to handle a possible case here, for example: | ||
| | -11 |
13 changes: 13 additions & 0 deletions
13
tests/build_tests/super_errors/expected/warning_8_mixed_range_example.res.expected
This file contains hidden or 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;33mWarning number 8[0m | ||
| [36m/.../fixtures/warning_8_mixed_range_example.res[0m:[2m4:3-6:3[0m | ||
|
|
||
| 2 [2m│[0m // example is a negative int, not a char. | ||
| 3 [2m│[0m let f = x => | ||
| [1;33m4[0m [2m│[0m [1;33mswitch x {[0m | ||
| [1;33m5[0m [2m│[0m [1;33m | '\x00' .. 0x7FFFFFFF => 1[0m | ||
| [1;33m6[0m [2m│[0m [1;33m }[0m | ||
| 7 [2m│[0m | ||
|
|
||
| You forgot to handle a possible case here, for example: | ||
| | -1 |
2 changes: 1 addition & 1 deletion
2
...rs/fixtures/pattern_interval_non_char.res → ...rrors/fixtures/pattern_interval_float.res
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| let f = x => | ||
| switch x { | ||
| | 1 .. 5 => "low" | ||
| | 1.0 .. 5.0 => "low" | ||
| | _ => "other" | ||
| } |
6 changes: 6 additions & 0 deletions
6
tests/build_tests/super_errors/fixtures/warning_8_int_range_example.res
This file contains hidden or 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,6 @@ | ||
| // All non-negative ints are covered, so the example is negative. | ||
| let f = x => | ||
| switch x { | ||
| | 0 .. 0x7FFFFFFF => true | ||
| | -10 .. -1 => false | ||
| } |
6 changes: 6 additions & 0 deletions
6
tests/build_tests/super_errors/fixtures/warning_8_mixed_range_example.res
This file contains hidden or 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,6 @@ | ||
| // A range from a char to an int covers all non-negative ints, so the | ||
| // example is a negative int, not a char. | ||
| let f = x => | ||
| switch x { | ||
| | '\x00' .. 0x7FFFFFFF => 1 | ||
| } |
This file contains hidden or 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,155 @@ | ||
| // Generated by ReScript, PLEASE EDIT WITH CARE | ||
|
|
||
| import * as Mocha from "mocha"; | ||
| import * as Test_utils from "./test_utils.mjs"; | ||
|
|
||
| function classify(x) { | ||
| if (x >= 10) { | ||
| if (x >= 32) { | ||
| if (x > 200 || x < 100) { | ||
| return "other"; | ||
| } else { | ||
| return "reversed"; | ||
| } | ||
| } else if (x >= 16) { | ||
| return "hex"; | ||
| } else { | ||
| return "other"; | ||
| } | ||
| } else if (x >= 0) { | ||
| if (x !== 0) { | ||
| return "digit"; | ||
| } else { | ||
| return "zero"; | ||
| } | ||
| } else if (x >= -5) { | ||
| return "negative"; | ||
| } else { | ||
| return "other"; | ||
| } | ||
| } | ||
|
|
||
| function ascii(x) { | ||
| if (x >= 91) { | ||
| if (x > 122 || x < 97) { | ||
| return "other"; | ||
| } else { | ||
| return "lower"; | ||
| } | ||
| } else if (x >= 65) { | ||
| return "upper"; | ||
| } else { | ||
| return "other"; | ||
| } | ||
| } | ||
|
|
||
| function large(x) { | ||
| if (x >= 0) { | ||
| if (x >= 1073741824) { | ||
| return "high"; | ||
| } else { | ||
| return "low"; | ||
| } | ||
| } else { | ||
| return "negative"; | ||
| } | ||
| } | ||
|
|
||
| function status(code) { | ||
| if (code >= 309) { | ||
| if (code >= 500) { | ||
| if (code >= 600) { | ||
| return "unknown"; | ||
| } else { | ||
| return "server error"; | ||
| } | ||
| } else if (code >= 400) { | ||
| return "client error"; | ||
| } else { | ||
| return "unknown"; | ||
| } | ||
| } | ||
| if (code < 200) { | ||
| return "unknown"; | ||
| } | ||
| if (code < 300) { | ||
| return "success"; | ||
| } | ||
| switch (code) { | ||
| case 300 : | ||
| case 303 : | ||
| case 304 : | ||
| case 305 : | ||
| case 306 : | ||
| return "unknown"; | ||
| case 301 : | ||
| case 302 : | ||
| case 307 : | ||
| case 308 : | ||
| return "redirect"; | ||
| } | ||
| } | ||
|
|
||
| function pair(a, b) { | ||
| if (a > 9 || a < 0) { | ||
| if (!(b > 9 || b < 0)) { | ||
| return "one"; | ||
| } | ||
| } else if (!(b > 9 || b < 0)) { | ||
| return "both"; | ||
| } | ||
| if (a > 9 || a < 0) { | ||
| return "none"; | ||
| } else { | ||
| return "one"; | ||
| } | ||
| } | ||
|
|
||
| Mocha.describe("Int_range_test", () => { | ||
| Mocha.test("ranges", () => { | ||
| Test_utils.eq("File \"int_range_test.res\", line 47, characters 7-14", classify(-5), "negative"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 48, characters 7-14", classify(-1), "negative"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 49, characters 7-14", classify(-6), "other"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 50, characters 7-14", classify(0), "zero"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 51, characters 7-14", classify(9), "digit"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 52, characters 7-14", classify(16), "hex"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 53, characters 7-14", classify(31), "hex"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 54, characters 7-14", classify(32), "other"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 55, characters 7-14", classify(150), "reversed"); | ||
| }); | ||
| Mocha.test("mixed bounds", () => { | ||
| Test_utils.eq("File \"int_range_test.res\", line 59, characters 7-14", ascii(/* 'q' */113), "lower"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 60, characters 7-14", ascii(81), "upper"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 61, characters 7-14", ascii(/* '!' */33), "other"); | ||
| }); | ||
| Mocha.test("large ranges", () => { | ||
| Test_utils.eq("File \"int_range_test.res\", line 65, characters 7-14", large(-2147483648), "negative"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 66, characters 7-14", large(0), "low"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 67, characters 7-14", large(1073741823), "low"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 68, characters 7-14", large(1073741824), "high"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 69, characters 7-14", large(2147483647), "high"); | ||
| }); | ||
| Mocha.test("status codes", () => { | ||
| Test_utils.eq("File \"int_range_test.res\", line 73, characters 7-14", status(204), "success"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 74, characters 7-14", status(302), "redirect"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 75, characters 7-14", status(304), "unknown"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 76, characters 7-14", status(404), "client error"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 77, characters 7-14", status(503), "server error"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 78, characters 7-14", status(600), "unknown"); | ||
| }); | ||
| Mocha.test("several columns", () => { | ||
| Test_utils.eq("File \"int_range_test.res\", line 82, characters 7-14", pair(1, 2), "both"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 83, characters 7-14", pair(1, 20), "one"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 84, characters 7-14", pair(20, 2), "one"); | ||
| Test_utils.eq("File \"int_range_test.res\", line 85, characters 7-14", pair(20, 20), "none"); | ||
| }); | ||
| }); | ||
|
|
||
| export { | ||
| classify, | ||
| ascii, | ||
| large, | ||
| status, | ||
| pair, | ||
| } | ||
| /* Not a pure module */ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.