V version: V 0.1.29 99dd72e
OS: macOS 10.15.6
What did you do?
Wrote a test
What did you expect to see?
No warnings or errors
What did you see instead?
An error
Haven't dug into the details but I noticed this test working in V 0.1.23 is no longer working in V 0.1.29 99dd72e.
$ tail -20 *.v
==> example.v <==
module example
pub fn x() []int {
return [1, 2, 3]
}
==> example_test.v <==
module example
fn test_x() {
assert array_eq(x(), [1, 2, 3])
if !array_eq(x(), [1, 2, 3]) {
println('x was not 1')
}
}
fn array_eq(a, b []int) bool {
if a.len != b.len {
return false
}
for i, v in a {
if v != b[i] {
return false
}
}
return true
}
$ v test example_test.v
----------------------------------- Testing... ---------------------------------
FAIL 55.918 ms example_test.v
example_test.v:5:2: error: `if` expression needs `else` clause
3 | fn test_x() {
4 | assert array_eq(x(), [1, 2, 3])
5 | if !array_eq(x(), [1, 2, 3]) {
| ~~
6 | println('x was not 1')
7 | }
--------------------------------------------------------------------------------
56.370 ms <=== total time spent running V _test.v files
ok, fail, skip, total = 0, 1, 0, 1
Is resolved by adding any other statement:
assert array_eq(x(), [1, 2, 3])
println(1)
Reduced test case:
fn f(a []int) bool {
return true
}
assert f([1,2,3])
if f([1,2,3]) {
println('x')
}
Fixed with latest V.