From 2574dce1747e6086127a97274a582189fbc1ece8 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sun, 26 Apr 2020 22:25:54 +0800 Subject: [PATCH] all: fix remaining `[]array` warnings --- examples/game_of_life/modules/automaton/automaton.v | 2 +- examples/mini_calculator.v | 2 +- vlib/arrays/arrays.v | 2 +- vlib/builtin/array_test.v | 2 +- vlib/builtin/js/array.v | 5 ++--- vlib/clipboard/clipboard_linux.c.v | 2 +- vlib/hash/wyhash/wyhash_test.v | 6 +++--- vlib/mysql/result.v | 6 +++--- vlib/net/http/cookie.v | 4 ++-- vlib/net/http/http_httpbin_test.v | 2 +- vlib/net/websocket/ws.v | 2 +- vlib/os/cmdline/cmdline.v | 2 +- vlib/pg/pg.v | 2 +- vlib/sqlite/sqlite.v | 4 ++-- vlib/sync/pool.v | 6 +++--- vlib/v/builder/msvc.v | 2 +- vlib/v/parser/parser.v | 4 ++-- vlib/v/parser/parser_test.v | 6 +++--- vlib/v/scanner/scanner_test.v | 2 +- vlib/v/tests/fn_test.v | 5 ++--- vlib/v/tests/generic_test.v | 2 +- 21 files changed, 34 insertions(+), 36 deletions(-) diff --git a/examples/game_of_life/modules/automaton/automaton.v b/examples/game_of_life/modules/automaton/automaton.v index af3fc88e37..f4ce7b2f87 100644 --- a/examples/game_of_life/modules/automaton/automaton.v +++ b/examples/game_of_life/modules/automaton/automaton.v @@ -80,7 +80,7 @@ pub fn (aa mut Automaton) update() { } pub fn gun() Automaton { - mut field := []array_int + mut field := []array_int{} field << [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] field << [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] field << [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] diff --git a/examples/mini_calculator.v b/examples/mini_calculator.v index b20617e865..c1531b5401 100644 --- a/examples/mini_calculator.v +++ b/examples/mini_calculator.v @@ -68,7 +68,7 @@ fn expr_to_rev_pol(expr string) ?[]string { // Evaluate the result of Reverse Polish Notation. fn eval_rev_pol(rev_pol []string) ?f64 { - mut stack := []f64 + mut stack := []f64{} for item in rev_pol { if is_num_string(item) { stack << item.f64() diff --git a/vlib/arrays/arrays.v b/vlib/arrays/arrays.v index c6e5070763..2c773187bb 100644 --- a/vlib/arrays/arrays.v +++ b/vlib/arrays/arrays.v @@ -2,7 +2,7 @@ module arrays /* pub fn range(start, end T) []T { - mut res := []T + mut res := []T{} for i := start; i < end; i++ { res << i } diff --git a/vlib/builtin/array_test.v b/vlib/builtin/array_test.v index da3fafa982..7c5eeb7831 100644 --- a/vlib/builtin/array_test.v +++ b/vlib/builtin/array_test.v @@ -4,7 +4,7 @@ const ( ) fn test_pointer() { - mut arr := []&int + mut arr := []&int{} a := 1 b := 2 c := 3 diff --git a/vlib/builtin/js/array.v b/vlib/builtin/js/array.v index 53d0fc2a95..11c26a2017 100644 --- a/vlib/builtin/js/array.v +++ b/vlib/builtin/js/array.v @@ -15,7 +15,7 @@ pub: } /* -// Private function, used by V (`nums := []int`) +// Private function, used by V (`nums := []int{}`) fn new_array(mylen, cap, elm_size int) array { arr := array { len: mylen @@ -130,6 +130,5 @@ pub fn (arr mut array) push_many(val voidptr, size int) { } pub fn free(voidptr) { - -} +} diff --git a/vlib/clipboard/clipboard_linux.c.v b/vlib/clipboard/clipboard_linux.c.v index 2947f222b0..587339ec92 100644 --- a/vlib/clipboard/clipboard_linux.c.v +++ b/vlib/clipboard/clipboard_linux.c.v @@ -377,7 +377,7 @@ fn (cb &Clipboard) pick_target(prop Property) C.Atom { } fn (cb &Clipboard) get_atoms(types ...AtomType) []C.Atom { - mut atoms := []C.Atom + mut atoms := []C.Atom{} for typ in types { atoms << cb.atoms[typ] } diff --git a/vlib/hash/wyhash/wyhash_test.v b/vlib/hash/wyhash/wyhash_test.v index f7b55a483d..75c890c185 100644 --- a/vlib/hash/wyhash/wyhash_test.v +++ b/vlib/hash/wyhash/wyhash_test.v @@ -28,15 +28,15 @@ fn test_wyhash() { } } -fn test_rand_u64() { +fn test_rand_u64() { seed := u64(111) - mut rand_nos := []u64 + mut rand_nos := []u64{} for _ in 0..40 { rand_no := wyhash.rand_u64(&seed) for r in rand_nos { assert rand_no != r } rand_nos << rand_no - } + } assert true } diff --git a/vlib/mysql/result.v b/vlib/mysql/result.v index 589205c08a..24ab36638c 100644 --- a/vlib/mysql/result.v +++ b/vlib/mysql/result.v @@ -41,7 +41,7 @@ pub fn (r Result) num_fields() int { } pub fn (r Result) rows() []Row { - mut rows := []Row + mut rows := []Row{} nr_cols := r.num_fields() for rr := r.fetch_row(); rr; rr = r.fetch_row() { mut row := Row{} @@ -58,7 +58,7 @@ pub fn (r Result) rows() []Row { } pub fn (r Result) fetch_fields() []Field { - mut fields := []Field + mut fields := []Field{} nr_cols := r.num_fields() orig_fields := mysql_fetch_fields(r.result) for i in 0..nr_cols { @@ -90,7 +90,7 @@ pub fn (r Result) fetch_fields() []Field { pub fn (f Field) str() string { return ' -{ +{ name: "$f.name" org_name: "$f.org_name" table: "$f.table" diff --git a/vlib/net/http/cookie.v b/vlib/net/http/cookie.v index ddc2ccc8e2..d2fb5598d0 100644 --- a/vlib/net/http/cookie.v +++ b/vlib/net/http/cookie.v @@ -46,7 +46,7 @@ pub fn read_set_cookies(h map[string][]string) []&Cookie { if cookie_count == 0 { return [] } - mut cookies := []&Cookie + mut cookies := []&Cookie{} for _, line in cookies_s { mut parts := line.trim_space().split(';') if parts.len == 1 && parts[0] == '' { @@ -153,7 +153,7 @@ pub fn read_cookies(h map[string][]string, filter string) []&Cookie { if lines.len == 0 { return [] } - mut cookies := []&Cookie + mut cookies := []&Cookie{} for _, _line in lines { mut line := _line.trim_space() mut part := '' diff --git a/vlib/net/http/http_httpbin_test.v b/vlib/net/http/http_httpbin_test.v index 9bb87f5eac..080d2fb7dd 100644 --- a/vlib/net/http/http_httpbin_test.v +++ b/vlib/net/http/http_httpbin_test.v @@ -18,7 +18,7 @@ fn http_fetch_mock(_methods []string, _config FetchConfig) ?[]Response { url := 'https://httpbin.org/' methods := if _methods.len == 0 { ['GET', 'POST', 'PATCH', 'PUT', 'DELETE'] } else { _methods } mut config := _config - mut result := []Response + mut result := []Response{} // Note: httpbin doesn't support head for method in methods { lmethod := method.to_lower() diff --git a/vlib/net/websocket/ws.v b/vlib/net/websocket/ws.v index 119f130e67..18854800bd 100644 --- a/vlib/net/websocket/ws.v +++ b/vlib/net/websocket/ws.v @@ -461,7 +461,7 @@ pub fn (ws mut Client) read() int { data: payload len: payload_len } - mut frags := []Fragment + mut frags := []Fragment{} mut size := u64(0) for f in ws.fragments { if f.len > 0 { diff --git a/vlib/os/cmdline/cmdline.v b/vlib/os/cmdline/cmdline.v index d9dd46cbce..d85ae11145 100644 --- a/vlib/os/cmdline/cmdline.v +++ b/vlib/os/cmdline/cmdline.v @@ -39,7 +39,7 @@ pub fn option(args []string, param string, def string) string { // what: ['test'] // ret: ['-stat'] pub fn options_before(args []string, what []string) []string { - mut args_before := []string {} + mut args_before := []string{} for a in args { if a in what { break diff --git a/vlib/pg/pg.v b/vlib/pg/pg.v index f38d4552fa..b76d3c8cda 100644 --- a/vlib/pg/pg.v +++ b/vlib/pg/pg.v @@ -52,7 +52,7 @@ pub fn connect(config pg.Config) ?DB { fn res_to_rows(res voidptr) []pg.Row { nr_rows := C.PQntuples(res) nr_cols := C.PQnfields(res) - mut rows := []pg.Row + mut rows := []pg.Row{} for i in 0..nr_rows { mut row := Row{} for j in 0..nr_cols { diff --git a/vlib/sqlite/sqlite.v b/vlib/sqlite/sqlite.v index 005193e125..96da51d462 100644 --- a/vlib/sqlite/sqlite.v +++ b/vlib/sqlite/sqlite.v @@ -63,10 +63,10 @@ pub fn (db DB) exec(query string) ([]Row,int) { C.sqlite3_prepare_v2(db.conn, query.str, -1, &stmt, 0) nr_cols := C.sqlite3_column_count(stmt) mut res := 0 - mut rows := []Row + mut rows := []Row{} for { res = C.sqlite3_step(stmt) - // Result Code SQLITE_ROW; Another row is available + // Result Code SQLITE_ROW; Another row is available if res != 100 { break } diff --git a/vlib/sync/pool.v b/vlib/sync/pool.v index 506873b796..7803bce9d5 100644 --- a/vlib/sync/pool.v +++ b/vlib/sync/pool.v @@ -178,7 +178,7 @@ pub fn (pool &PoolProcessor) get_int_item(idx int) int { // TODO: uncomment, when generics work again // get_results - can be called to get a list of type safe results. //pub fn (pool &PoolProcessor) get_results() []T { -// mut res := []T +// mut res := []T{} // for i in 0 .. pool.results.len { // res << *(&T(pool.results[i])) // } @@ -234,14 +234,14 @@ pub fn (pool mut PoolProcessor) work_on_items_i(items []int) { } pub fn (pool &PoolProcessor) get_results_s() []SResult { - mut res := []SResult + mut res := []SResult{} for i in 0 .. pool.results.len { res << *(&SResult(pool.results[i])) } return res } pub fn (pool &PoolProcessor) get_results_i() []IResult { - mut res := []IResult + mut res := []IResult{} for i in 0 .. pool.results.len { res << *(&IResult(pool.results[i])) } diff --git a/vlib/v/builder/msvc.v b/vlib/v/builder/msvc.v index 04d9130ca9..ced37237a4 100644 --- a/vlib/v/builder/msvc.v +++ b/vlib/v/builder/msvc.v @@ -223,7 +223,7 @@ pub fn (mut v Builder) cc_msvc() { v.pref.out_name += '.exe' } v.pref.out_name = os.real_path(v.pref.out_name) - // alibs := []string // builtin.o os.o http.o etc + // alibs := []string{} // builtin.o os.o http.o etc if v.pref.build_mode == .build_module { // Compile only a << '/c' diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index abac8fea12..4a0e9edc3d 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -95,7 +95,7 @@ pub fn parse_file(path string, table &table.Table, comments_mode scanner.Comment stmts << mstmt // imports /* - mut imports := []ast.Import + mut imports := []ast.Import{} for p.tok.kind == .key_import { imports << p.import_stmt() } @@ -1102,7 +1102,7 @@ fn (mut p Parser) enum_decl() ast.EnumDecl { name := p.prepend_mod(enum_name) p.check(.lcbr) mut vals := []string{} - // mut default_exprs := []ast.Expr + // mut default_exprs := []ast.Expr{} mut fields := []ast.EnumField{} for p.tok.kind != .eof && p.tok.kind != .rcbr { pos := p.tok.position() diff --git a/vlib/v/parser/parser_test.v b/vlib/v/parser/parser_test.v index 9008ae7e88..a7b2954021 100644 --- a/vlib/v/parser/parser_test.v +++ b/vlib/v/parser/parser_test.v @@ -40,7 +40,7 @@ fn test_eval() { start_pos: 0 parent: 0 } - mut stmts := []ast.Stmt + mut stmts := []ast.Stmt{} for input in inputs { stmts << parse_stmt(input, table, scope) } @@ -103,7 +103,7 @@ fn test_one() { start_pos: 0 parent: 0 } - mut e := []ast.Stmt + mut e := []ast.Stmt{} for line in input { e << parse_stmt(line, table, scope) } @@ -194,7 +194,7 @@ fn test_parse_expr() { '-a + 1;', '2 + 2;', ] - mut e := []ast.Stmt + mut e := []ast.Stmt{} table := table.new_table() vpref := &pref.Preferences{} mut checker := checker.new_checker(table, vpref) diff --git a/vlib/v/scanner/scanner_test.v b/vlib/v/scanner/scanner_test.v index a94eee2a03..8cd2caa86e 100644 --- a/vlib/v/scanner/scanner_test.v +++ b/vlib/v/scanner/scanner_test.v @@ -8,7 +8,7 @@ import v.token fn test_scan() { text := 'println(2 + 3)' mut scanner := new_scanner(text, .skip_comments) - mut token_kinds := []token.Kind + mut token_kinds := []token.Kind{} for { tok := scanner.scan() if tok.kind == .eof { diff --git a/vlib/v/tests/fn_test.v b/vlib/v/tests/fn_test.v index b93890471d..790c4a28f7 100644 --- a/vlib/v/tests/fn_test.v +++ b/vlib/v/tests/fn_test.v @@ -134,7 +134,7 @@ fn test_anon_fn() { println('hello from f1') } f1(1) - + f2 := fn(a int) int { println('hello from f2') return 10 @@ -171,7 +171,7 @@ struct MySt { f MyFn } fn test_fn_type_call() { - mut arr := []MyFn + mut arr := []MyFn{} arr << MyFn(test) // TODO: `arr[0](10)` // assert arr[0](10) == 1010 @@ -185,4 +185,3 @@ fn test_fn_type_call() { st1 := &MySt{f:test} assert st1.f(10) == 1010 } - diff --git a/vlib/v/tests/generic_test.v b/vlib/v/tests/generic_test.v index 8383aa0925..54e01d0947 100644 --- a/vlib/v/tests/generic_test.v +++ b/vlib/v/tests/generic_test.v @@ -15,7 +15,7 @@ fn sum(l []T) T { } fn map_f(l []T, f fn(T)U) []U { - mut r := []U + mut r := []U{} for e in l { r << f(e) }