Skip to content

Commit

Permalink
add generics test
Browse files Browse the repository at this point in the history
  • Loading branch information
shove70 committed Dec 27, 2023
1 parent 5c3b54b commit d45e170
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 30 deletions.
81 changes: 51 additions & 30 deletions vlib/v/checker/tests/array_init_without_init_value_err.out
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,60 @@ vlib/v/checker/tests/array_init_without_init_value_err.vv:7:13: warning: fixed a
| ~~~~~~~~~
8 | println(fixed_a)
9 | }
vlib/v/checker/tests/array_init_without_init_value_err.vv:13:11: warning: arrays of references need to be initialized right away, therefore `len:` cannot be used (unless inside `unsafe`)
11 | // test references uninitialized.
12 | fn main_ref() {
13 | println(*[]&int{len: 1}[0])
vlib/v/checker/tests/array_init_without_init_value_err.vv:20:11: warning: arrays of references need to be initialized right away, therefore `len:` cannot be used (unless inside `unsafe`)
18 | // test references uninitialized.
19 | fn main_ref() {
20 | println(*[]&int{len: 1}[0])
| ~~~~~~~
14 | println([1]&int{})
15 | _ = [][1]&int{len: 1}[0][0]
vlib/v/checker/tests/array_init_without_init_value_err.vv:14:10: warning: fixed arrays of references need to be initialized right away (unless inside `unsafe`)
12 | fn main_ref() {
13 | println(*[]&int{len: 1}[0])
14 | println([1]&int{})
21 | println([1]&int{})
22 | _ = [][1]&int{len: 1}[0][0]
vlib/v/checker/tests/array_init_without_init_value_err.vv:21:10: warning: fixed arrays of references need to be initialized right away (unless inside `unsafe`)
19 | fn main_ref() {
20 | println(*[]&int{len: 1}[0])
21 | println([1]&int{})
| ~~~~~~~~~
15 | _ = [][1]&int{len: 1}[0][0]
16 | _ = []map[int]&int{len: 1}
vlib/v/checker/tests/array_init_without_init_value_err.vv:15:6: warning: arrays of references need to be initialized right away, therefore `len:` cannot be used (unless inside `unsafe`)
13 | println(*[]&int{len: 1}[0])
14 | println([1]&int{})
15 | _ = [][1]&int{len: 1}[0][0]
22 | _ = [][1]&int{len: 1}[0][0]
23 | _ = []map[int]&int{len: 1}
vlib/v/checker/tests/array_init_without_init_value_err.vv:22:6: warning: arrays of references need to be initialized right away, therefore `len:` cannot be used (unless inside `unsafe`)
20 | println(*[]&int{len: 1}[0])
21 | println([1]&int{})
22 | _ = [][1]&int{len: 1}[0][0]
| ~~~~~~~~~~
16 | _ = []map[int]&int{len: 1}
17 | }
vlib/v/checker/tests/array_init_without_init_value_err.vv:16:6: warning: arrays of references need to be initialized right away, therefore `len:` cannot be used (unless inside `unsafe`)
14 | println([1]&int{})
15 | _ = [][1]&int{len: 1}[0][0]
16 | _ = []map[int]&int{len: 1}
23 | _ = []map[int]&int{len: 1}
24 | }
vlib/v/checker/tests/array_init_without_init_value_err.vv:23:6: warning: arrays of references need to be initialized right away, therefore `len:` cannot be used (unless inside `unsafe`)
21 | println([1]&int{})
22 | _ = [][1]&int{len: 1}[0][0]
23 | _ = []map[int]&int{len: 1}
| ~~~~~~~~~~~~~~~
17 | }
18 |
vlib/v/checker/tests/array_init_without_init_value_err.vv:33:22: warning: arrays of interfaces need to be initialized right away, therefore `len:` cannot be used (unless inside `unsafe`)
31 |
32 | fn main_interface() {
33 | mut parsed_lines := []MObject{len: 9}
24 | }
25 |
vlib/v/checker/tests/array_init_without_init_value_err.vv:40:22: warning: arrays of interfaces need to be initialized right away, therefore `len:` cannot be used (unless inside `unsafe`)
38 |
39 | fn main_interface() {
40 | mut parsed_lines := []MObject{len: 9}
| ~~~~~~~~~~
34 | println(parsed_lines)
35 | }
41 | println(parsed_lines)
42 | }
vlib/v/checker/tests/array_init_without_init_value_err.vv:12:7: warning: arrays of sumtypes need to be initialized right away, therefore `len:` cannot be used (unless inside `unsafe`)
10 |
11 | fn main_sum_type_2[T]() {
12 | a := []T{len: 10}
| ~~~~
13 | println(a)
14 | fixed_a := [10]T{}
vlib/v/checker/tests/array_init_without_init_value_err.vv:14:13: warning: fixed arrays of sumtypes need to be initialized right away (unless inside `unsafe`)
12 | a := []T{len: 10}
13 | println(a)
14 | fixed_a := [10]T{}
| ~~~~~~~
15 | println(fixed_a)
16 | }
vlib/v/checker/tests/array_init_without_init_value_err.vv:45:22: warning: arrays of interfaces need to be initialized right away, therefore `len:` cannot be used (unless inside `unsafe`)
43 |
44 | fn main_interface_2[T]() {
45 | mut parsed_lines := []T{len: 9}
| ~~~~
46 | println(parsed_lines)
47 | }

16 changes: 16 additions & 0 deletions vlib/v/checker/tests/array_init_without_init_value_err.vv
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ fn main_sum_type() {
println(fixed_a)
}

fn main_sum_type_2[T]() {
a := []T{len: 10}
println(a)
fixed_a := [10]T{}
println(fixed_a)
}

// test references uninitialized.
fn main_ref() {
println(*[]&int{len: 1}[0])
Expand All @@ -34,8 +41,17 @@ fn main_interface() {
println(parsed_lines)
}

fn main_interface_2[T]() {
mut parsed_lines := []T{len: 9}
println(parsed_lines)
}

fn main() {
main_sum_type()
main_sum_type_2[Foo]()

main_ref()

main_interface()
main_interface_2[MObject]()
}

0 comments on commit d45e170

Please sign in to comment.