-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checker: support lambda expressions in array methods like `a.map(|x|x…
…*10)` too (#19424)
- Loading branch information
Showing
7 changed files
with
202 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const a = [4, 5, 1, 2, 5, 9] | ||
|
||
fn test_map() { | ||
assert a.map(it) == a | ||
assert a.map(it * 10) == [40, 50, 10, 20, 50, 90] | ||
// | ||
assert a.map(|x| x) == a | ||
assert a.map(|x| x * 10) == [40, 50, 10, 20, 50, 90] | ||
assert a.map(|x| 'x: ${x}') == ['x: 4', 'x: 5', 'x: 1', 'x: 2', 'x: 5', 'x: 9'] | ||
assert a.map(|x| f64(x) * 10.0) == [40.0, 50.0, 10.0, 20.0, 50.0, 90.0] | ||
} | ||
|
||
fn test_filter() { | ||
assert a.filter(it > 4) == [5, 5, 9] | ||
assert a.filter(it < 4) == [1, 2] | ||
// | ||
assert a.filter(|x| x > 4) == [5, 5, 9] | ||
assert a.filter(|x| x < 4) == [1, 2] | ||
} | ||
|
||
fn test_any() { | ||
assert a.any(it > 4) | ||
assert !a.any(it > 40) | ||
|
||
assert a.any(|x| x > 4) | ||
assert !a.any(|x| x > 40) | ||
} | ||
|
||
fn test_all() { | ||
assert !a.all(it > 4) | ||
assert a.all(it < 40) | ||
|
||
assert !a.all(|x| x > 4) | ||
assert a.all(|x| x < 40) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
vlib/v/checker/tests/lambda_expression_in_map.vv:3:12: error: lambda expressions used in the builtin array methods require exactly 1 parameter | ||
1 | a := [4, 5] | ||
2 | dump(a.map(it)) | ||
3 | dump(a.map(|| 5)) | ||
| ~~ | ||
4 | dump(a.map(|x| 5 * x)) | ||
5 | dump(a.map(|x| x)) | ||
vlib/v/checker/tests/lambda_expression_in_map.vv:6:12: error: lambda expressions used in the builtin array methods require exactly 1 parameter | ||
4 | dump(a.map(|x| 5 * x)) | ||
5 | dump(a.map(|x| x)) | ||
6 | dump(a.map(|x, y| x)) | ||
| ^ |
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,6 @@ | ||
a := [4, 5] | ||
dump(a.map(it)) | ||
dump(a.map(|| 5)) | ||
dump(a.map(|x| 5 * x)) | ||
dump(a.map(|x| x)) | ||
dump(a.map(|x, y| x)) |
Oops, something went wrong.