-
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 and cleanup uninitialized checks for container elements …
…when has len(fix vlang#20272)
- Loading branch information
Showing
9 changed files
with
159 additions
and
119 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
14 changes: 0 additions & 14 deletions
14
vlib/v/checker/tests/array_init_sum_type_without_init_value_and_len_err.out
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
vlib/v/checker/tests/array_init_sum_type_without_init_value_and_len_err.vv
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
vlib/v/checker/tests/array_init_without_init_value_err.out
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,70 @@ | ||
vlib/v/checker/tests/array_init_without_init_value_err.vv:5:7: warning: arrays of sumtypes need to be initialized right away, therefore `len:` cannot be used (unless inside `unsafe`, or if you also use `init:`) | ||
3 | | ||
4 | fn main_sum_type() { | ||
5 | a := []Foo{len: 10} | ||
| ~~~~~~ | ||
6 | println(a) | ||
7 | fixed_a := [10]Foo{} | ||
vlib/v/checker/tests/array_init_without_init_value_err.vv:7:13: warning: fixed arrays of sumtypes need to be initialized right away (unless inside `unsafe`) | ||
5 | a := []Foo{len: 10} | ||
6 | println(a) | ||
7 | fixed_a := [10]Foo{} | ||
| ~~~~~~~~~ | ||
8 | println(fixed_a) | ||
9 | } | ||
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`, or if you also use `init:`) | ||
18 | // test references uninitialized. | ||
19 | fn main_ref() { | ||
20 | println(*[]&int{len: 1}[0]) | ||
| ~~~~~~~ | ||
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{}) | ||
| ~~~~~~~~~ | ||
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`, or if you also use `init:`) | ||
20 | println(*[]&int{len: 1}[0]) | ||
21 | println([1]&int{}) | ||
22 | _ = [][1]&int{len: 1}[0][0] | ||
| ~~~~~~~~~~ | ||
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`, or if you also use `init:`) | ||
21 | println([1]&int{}) | ||
22 | _ = [][1]&int{len: 1}[0][0] | ||
23 | _ = []map[int]&int{len: 1} | ||
| ~~~~~~~~~~~~~~~ | ||
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`, or if you also use `init:`) | ||
38 | | ||
39 | fn main_interface() { | ||
40 | mut parsed_lines := []MObject{len: 9} | ||
| ~~~~~~~~~~ | ||
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`, or if you also use `init:`) | ||
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`, or if you also use `init:`) | ||
43 | | ||
44 | fn main_interface_2[T]() { | ||
45 | mut parsed_lines := []T{len: 9} | ||
| ~~~~ | ||
46 | println(parsed_lines) | ||
47 | } |
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,57 @@ | ||
// test sum_types uninitialized. | ||
type Foo = int | string | ||
|
||
fn main_sum_type() { | ||
a := []Foo{len: 10} | ||
println(a) | ||
fixed_a := [10]Foo{} | ||
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]) | ||
println([1]&int{}) | ||
_ = [][1]&int{len: 1}[0][0] | ||
_ = []map[int]&int{len: 1} | ||
} | ||
|
||
// test interfaces uninitialized. | ||
interface MObject { | ||
give_string() string | ||
} | ||
|
||
struct LeStruct { | ||
le_string string | ||
} | ||
|
||
fn (a LeStruct) give_string() string { | ||
return 'V' | ||
} | ||
|
||
fn main_interface() { | ||
mut parsed_lines := []MObject{len: 9} | ||
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]() | ||
} |
7 changes: 0 additions & 7 deletions
7
vlib/v/checker/tests/array_of_interfaces_with_len_without_init.out
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
vlib/v/checker/tests/array_of_interfaces_with_len_without_init.vv
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.