forked from vlang/v
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checker: fix generic comparison for conditional assignment (vlang#19401)
- Loading branch information
1 parent
6fb7266
commit 569ad61
Showing
2 changed files
with
36 additions
and
0 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
21 changes: 21 additions & 0 deletions
21
vlib/v/tests/generic_comparison_for_conditional_assign_test.v
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,21 @@ | ||
fn clip[N](x []N, min N, max N) []N { | ||
mut result := []N{cap: x.len} | ||
for value in x { | ||
result << if value < min { | ||
min | ||
} else if value > max { | ||
max | ||
} else { | ||
value | ||
} | ||
} | ||
return result | ||
} | ||
|
||
fn test_generic_comparison_for_conditional_assign() { | ||
a := [1, 2, 3, 4, 5] | ||
dump(a) | ||
b := clip(a, 2, 4) | ||
dump(b) | ||
assert b == [2, 2, 3, 4, 4] | ||
} |