V: V Fmt bug compendium

Created on 5 Nov 2020  路  2Comments  路  Source: vlang/v

Running vfmt over the whole of vlib


  1. fixed
  2. Only happens in match statements

    fixed

  3. fixed
  4. (#6851) Only happens in structs


  5. that is hard to fix, and will remain as is for now

  6. Related to the one above: it goes through and replaces the entire files template param references

  7. I am not sure what the problem is - the additional space?
  8. I actually cannot figure out what it has done here...
diff --git a/vlib/v/tests/map_and_array_with_fns_test.v b/vlib/v/tests/map_and_array_with_fns_test.v
index c949b25f3..bc12955ee 100644
--- a/vlib/v/tests/map_and_array_with_fns_test.v
+++ b/vlib/v/tests/map_and_array_with_fns_test.v
@@ -37,9 +37,60 @@ fn test_array_with_fns() {
 }

 fn test_map_with_fns() {
-   mut a := {'one':foo, 'two':foo2}
+   mut a := {
+       'one': foo
+       'two': foo2
+   }
+   assert a.len == 2
+   assert fn foo(a string, b string) int {
+   return 10 + a.len + b.len
+}
+
+fn foo2(a string, b string) int {
+   return 20 + a.len + b.len
+}
+
+fn test_array_with_fns() {
+   mut a := [foo, foo2]
+   assert a.len == 2
+   assert (a != [foo, foo2]) == false
+   assert (foo in a) == true
+   f0 := a[0]
+   assert f0('xx', '') == 12
+   f1 := a[1]
+   assert f1('yyy', '') == 23
+   a[0], a[1] = a[1], a[0]
+   f2 := a[0]
+   assert f2('zzzz', '') == 24
+   f3 := a[1]
+   assert f3('aaaaa', '') == 15
+   mut b := [foo]
+   assert (foo2 !in b) == true
+   b[0] = a[0]
+   f4 := b[0]
+   assert f4('bbbbbb', '') == 26
+   for func in b {
+       assert func('ccccccc', '') == 27
+   }
+   b = []
+   b << foo
+   b << [foo2]
+   assert (b == [foo, foo2]) == true
+   f5 := b[0]
+   assert f5('dddddddd', '') == 18
+}
+
+fn test_map_with_fns() {
+   mut a := {
+       'one': foo
+       'two': foo2
+   }
    assert a.len == 2
-   assert (a == {'one':foo, 'two':foo2}) == true
+   assert (a == {
+       'one': foo
+       'two': foo2
+   }) ==
+       true
    f0 := a['one']
    assert f0('xx', '') == 12
    f1 := a['two']
@@ -49,7 +100,9 @@ fn test_map_with_fns() {
    assert f2('zzzz', '') == 24
    f3 := a['two']
    assert f3('aaaaa', '') == 15
-   mut b := {'one':foo}
+   mut b := {
+       'one': foo
+   }
    b['one'] = a['one']
    f4 := b['one']
    assert f4('bbbbbb', '') == 26
  1. Neither here
diff --git a/vlib/v/tests/if_expression_test.v b/vlib/v/tests/if_expression_test.v
index b5b82faac..e2030c290 100644
--- a/vlib/v/tests/if_expression_test.v
+++ b/vlib/v/tests/if_expression_test.v
@@ -22,11 +22,183 @@ fn test_if_expression_with_stmts() {
    }
    assert a == 1
    mut b := 0
-   b = if false {
-       42
+   b = if false { 42 } else { 24 }
+   assert b == 24
+}
+
+fn noop() {
+}
+
+fn test_if_expression_with_function_assign() {
+   a := if true {
+       my_fn := noop
+       my_fn()
+       0
+   } else {
+       1
+   }
+   assert a == 0
+}
+
+fn get_bool_str(b bool) string {
+   return b.str()
+}
+
+fn test_if_expression_mutate_var() {
+   mut b := false
+   r := b && if true {
+       b = true
+       true
+   } else {
+       true
+   }
+   assert r == false
+   // test in function call
+   assert fn test_if_expression_precedence_false_condition() {
+   b := 10
+   c := 20
+   res := 1 + if b > c { b } else { c } + 1
+   assert res == c + 2
+}
+
+fn test_if_expression_precedence_true_condition() {
+   b := 20
+   c := 10
+   res := 1 + if b > c { b } else { c } + 1
+   assert res == b + 2
+}
+
+fn test_if_expression_with_stmts() {
+   a := if true {
+       b := 1
+       b
+   } else {
+       b := 4
+       b
+   }
+   assert a == 1
+   mut b := 0
+   b = if false { 42 } else { 24 }
+   assert b == 24
+}
+
+fn noop() {
+}
+
+fn test_if_expression_with_function_assign() {
+   a := if true {
+       my_fn := noop
+       my_fn()
+       0
+   } else {
+       1
+   }
+   assert a == 0
+}
+
+fn get_bool_str(b bool) string {
+   return b.str()
+}
+
+fn test_if_expression_mutate_var() {
+   mut b := false
+   r := b && if true {
+       b = true
+       true
+   } else {
+       true
+   }
+   assert r == false
+   // test in function call
+   assert get_bool_str(b && if true {
+       b = true
+       true
+   } else {
+       true
+   }) ==
+       'false'
+   // test on method call
+   assert fn test_if_expression_precedence_false_condition() {
+   b := 10
+   c := 20
+   res := 1 + if b > c { b } else { c } + 1
+   assert res == c + 2
+}
+
+fn test_if_expression_precedence_true_condition() {
+   b := 20
+   c := 10
+   res := 1 + if b > c { b } else { c } + 1
+   assert res == b + 2
+}
+
+fn test_if_expression_with_stmts() {
+   a := if true {
+       b := 1
+       b
    } else {
-       24
+       b := 4
+       b
    }
+   assert a == 1
+   mut b := 0
+   b = if false { 42 } else { 24 }
+   assert b == 24
+}
+
+fn noop() {
+}
+
+fn test_if_expression_with_function_assign() {
+   a := if true {
+       my_fn := noop
+       my_fn()
+       0
+   } else {
+       1
+   }
+   assert a == 0
+}
+
+fn get_bool_str(b bool) string {
+   return b.str()
+}
+
+fn test_if_expression_mutate_var() {
+   mut b := false
+   r := b && if true {
+       b = true
+       true
+   } else {
+       true
+   }
+   assert r == false
+   // test in function call
+   assert fn test_if_expression_precedence_false_condition() {
+   b := 10
+   c := 20
+   res := 1 + if b > c { b } else { c } + 1
+   assert res == c + 2
+}
+
+fn test_if_expression_precedence_true_condition() {
+   b := 20
+   c := 10
+   res := 1 + if b > c { b } else { c } + 1
+   assert res == b + 2
+}
+
+fn test_if_expression_with_stmts() {
+   a := if true {
+       b := 1
+       b
+   } else {
+       b := 4
+       b
+   }
+   assert a == 1
+   mut b := 0
+   b = if false { 42 } else { 24 }
    assert b == 24
 }

@@ -63,14 +235,16 @@ fn test_if_expression_mutate_var() {
        true
    } else {
        true
-   }) == 'false'
+   }) ==
+       'false'
    // test on method call
    assert (b && if true {
        b = true
        true
    } else {
        true
-   }).str() == 'false'
+   }).str() ==
+       'false'
    // test on array
    mut a := [1, 2]
    assert a.len == 2 && if true {
  1. See here as is the same with 19, 20 where it just starts pasting the file back into the file...
enum Color {
    red
    green
    blue
}

pub fn (c Color) str() string {
    return 'tmp'
}

fn test_match_integers() {
    mut a := 3
    mut b := 0
    match a {
        2 {
            println('two')
        }
        3 {
            println('three')
            b = 3
        }
        4 {
            println('four')
        }
        else {
            println('???')
        }
    }
    assert b == 3
    assert enum Color {
    red
    green
    blue
}

pub fn (c Color) str() string {
    return 'tmp'
}

fn test_match_integers() {
    mut a := 3
    mut b := 0
    match a {
        2 {
            println('two')
        }
        3 {
            println('three')
            b = 3
        }
        4 {
            println('four')
        }
        else {
            println('???')
        }
    }
    assert b == 3
    assert match 2 {
        1 { 2 }
        2 { 3 }
        else { 5 }
    } ==
        3
    assert enum Color {
    red
    green
    blue
}
Bug vfmt

Most helpful comment

Such mega issues, especially when they include screenshots, and not code examples, are unwieldy.

I've fixed some of them, but it is getting harder to keep track of which ones exactly :-| .

All 2 comments

Such mega issues, especially when they include screenshots, and not code examples, are unwieldy.

I've fixed some of them, but it is getting harder to keep track of which ones exactly :-| .

Yeah apologies ill get some text diffs in there sometime :thumbsup:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

elimisteve picture elimisteve  路  3Comments

shouji-kazuo picture shouji-kazuo  路  3Comments

XVilka picture XVilka  路  3Comments

markgraydev picture markgraydev  路  3Comments

PavelVozenilek picture PavelVozenilek  路  3Comments