all: fix remaining `[]array` warnings

pull/4696/head
yuyi 2020-04-26 22:25:54 +08:00 committed by GitHub
parent 9f4d498ff1
commit 2574dce174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 34 additions and 36 deletions

View File

@ -80,7 +80,7 @@ pub fn (aa mut Automaton) update() {
} }
pub fn gun() Automaton { 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] 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]

View File

@ -68,7 +68,7 @@ fn expr_to_rev_pol(expr string) ?[]string {
// Evaluate the result of Reverse Polish Notation. // Evaluate the result of Reverse Polish Notation.
fn eval_rev_pol(rev_pol []string) ?f64 { fn eval_rev_pol(rev_pol []string) ?f64 {
mut stack := []f64 mut stack := []f64{}
for item in rev_pol { for item in rev_pol {
if is_num_string(item) { if is_num_string(item) {
stack << item.f64() stack << item.f64()

View File

@ -2,7 +2,7 @@ module arrays
/* /*
pub fn range<T>(start, end T) []T { pub fn range<T>(start, end T) []T {
mut res := []T mut res := []T{}
for i := start; i < end; i++ { for i := start; i < end; i++ {
res << i res << i
} }

View File

@ -4,7 +4,7 @@ const (
) )
fn test_pointer() { fn test_pointer() {
mut arr := []&int mut arr := []&int{}
a := 1 a := 1
b := 2 b := 2
c := 3 c := 3

View File

@ -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 { fn new_array(mylen, cap, elm_size int) array {
arr := array { arr := array {
len: mylen len: mylen
@ -130,6 +130,5 @@ pub fn (arr mut array) push_many(val voidptr, size int) {
} }
pub fn free(voidptr) { pub fn free(voidptr) {
}
}

View File

@ -377,7 +377,7 @@ fn (cb &Clipboard) pick_target(prop Property) C.Atom {
} }
fn (cb &Clipboard) get_atoms(types ...AtomType) []C.Atom { fn (cb &Clipboard) get_atoms(types ...AtomType) []C.Atom {
mut atoms := []C.Atom mut atoms := []C.Atom{}
for typ in types { for typ in types {
atoms << cb.atoms[typ] atoms << cb.atoms[typ]
} }

View File

@ -28,15 +28,15 @@ fn test_wyhash() {
} }
} }
fn test_rand_u64() { fn test_rand_u64() {
seed := u64(111) seed := u64(111)
mut rand_nos := []u64 mut rand_nos := []u64{}
for _ in 0..40 { for _ in 0..40 {
rand_no := wyhash.rand_u64(&seed) rand_no := wyhash.rand_u64(&seed)
for r in rand_nos { for r in rand_nos {
assert rand_no != r assert rand_no != r
} }
rand_nos << rand_no rand_nos << rand_no
} }
assert true assert true
} }

View File

@ -41,7 +41,7 @@ pub fn (r Result) num_fields() int {
} }
pub fn (r Result) rows() []Row { pub fn (r Result) rows() []Row {
mut rows := []Row mut rows := []Row{}
nr_cols := r.num_fields() nr_cols := r.num_fields()
for rr := r.fetch_row(); rr; rr = r.fetch_row() { for rr := r.fetch_row(); rr; rr = r.fetch_row() {
mut row := Row{} mut row := Row{}
@ -58,7 +58,7 @@ pub fn (r Result) rows() []Row {
} }
pub fn (r Result) fetch_fields() []Field { pub fn (r Result) fetch_fields() []Field {
mut fields := []Field mut fields := []Field{}
nr_cols := r.num_fields() nr_cols := r.num_fields()
orig_fields := mysql_fetch_fields(r.result) orig_fields := mysql_fetch_fields(r.result)
for i in 0..nr_cols { for i in 0..nr_cols {
@ -90,7 +90,7 @@ pub fn (r Result) fetch_fields() []Field {
pub fn (f Field) str() string { pub fn (f Field) str() string {
return ' return '
{ {
name: "$f.name" name: "$f.name"
org_name: "$f.org_name" org_name: "$f.org_name"
table: "$f.table" table: "$f.table"

View File

@ -46,7 +46,7 @@ pub fn read_set_cookies(h map[string][]string) []&Cookie {
if cookie_count == 0 { if cookie_count == 0 {
return [] return []
} }
mut cookies := []&Cookie mut cookies := []&Cookie{}
for _, line in cookies_s { for _, line in cookies_s {
mut parts := line.trim_space().split(';') mut parts := line.trim_space().split(';')
if parts.len == 1 && parts[0] == '' { 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 { if lines.len == 0 {
return [] return []
} }
mut cookies := []&Cookie mut cookies := []&Cookie{}
for _, _line in lines { for _, _line in lines {
mut line := _line.trim_space() mut line := _line.trim_space()
mut part := '' mut part := ''

View File

@ -18,7 +18,7 @@ fn http_fetch_mock(_methods []string, _config FetchConfig) ?[]Response {
url := 'https://httpbin.org/' url := 'https://httpbin.org/'
methods := if _methods.len == 0 { ['GET', 'POST', 'PATCH', 'PUT', 'DELETE'] } else { _methods } methods := if _methods.len == 0 { ['GET', 'POST', 'PATCH', 'PUT', 'DELETE'] } else { _methods }
mut config := _config mut config := _config
mut result := []Response mut result := []Response{}
// Note: httpbin doesn't support head // Note: httpbin doesn't support head
for method in methods { for method in methods {
lmethod := method.to_lower() lmethod := method.to_lower()

View File

@ -461,7 +461,7 @@ pub fn (ws mut Client) read() int {
data: payload data: payload
len: payload_len len: payload_len
} }
mut frags := []Fragment mut frags := []Fragment{}
mut size := u64(0) mut size := u64(0)
for f in ws.fragments { for f in ws.fragments {
if f.len > 0 { if f.len > 0 {

View File

@ -39,7 +39,7 @@ pub fn option(args []string, param string, def string) string {
// what: ['test'] // what: ['test']
// ret: ['-stat'] // ret: ['-stat']
pub fn options_before(args []string, what []string) []string { pub fn options_before(args []string, what []string) []string {
mut args_before := []string {} mut args_before := []string{}
for a in args { for a in args {
if a in what { if a in what {
break break

View File

@ -52,7 +52,7 @@ pub fn connect(config pg.Config) ?DB {
fn res_to_rows(res voidptr) []pg.Row { fn res_to_rows(res voidptr) []pg.Row {
nr_rows := C.PQntuples(res) nr_rows := C.PQntuples(res)
nr_cols := C.PQnfields(res) nr_cols := C.PQnfields(res)
mut rows := []pg.Row mut rows := []pg.Row{}
for i in 0..nr_rows { for i in 0..nr_rows {
mut row := Row{} mut row := Row{}
for j in 0..nr_cols { for j in 0..nr_cols {

View File

@ -63,10 +63,10 @@ pub fn (db DB) exec(query string) ([]Row,int) {
C.sqlite3_prepare_v2(db.conn, query.str, -1, &stmt, 0) C.sqlite3_prepare_v2(db.conn, query.str, -1, &stmt, 0)
nr_cols := C.sqlite3_column_count(stmt) nr_cols := C.sqlite3_column_count(stmt)
mut res := 0 mut res := 0
mut rows := []Row mut rows := []Row{}
for { for {
res = C.sqlite3_step(stmt) res = C.sqlite3_step(stmt)
// Result Code SQLITE_ROW; Another row is available // Result Code SQLITE_ROW; Another row is available
if res != 100 { if res != 100 {
break break
} }

View File

@ -178,7 +178,7 @@ pub fn (pool &PoolProcessor) get_int_item(idx int) int {
// TODO: uncomment, when generics work again // TODO: uncomment, when generics work again
// get_results - can be called to get a list of type safe results. // get_results - can be called to get a list of type safe results.
//pub fn (pool &PoolProcessor) get_results<T>() []T { //pub fn (pool &PoolProcessor) get_results<T>() []T {
// mut res := []T // mut res := []T{}
// for i in 0 .. pool.results.len { // for i in 0 .. pool.results.len {
// res << *(&T(pool.results[i])) // 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 { pub fn (pool &PoolProcessor) get_results_s() []SResult {
mut res := []SResult mut res := []SResult{}
for i in 0 .. pool.results.len { for i in 0 .. pool.results.len {
res << *(&SResult(pool.results[i])) res << *(&SResult(pool.results[i]))
} }
return res return res
} }
pub fn (pool &PoolProcessor) get_results_i() []IResult { pub fn (pool &PoolProcessor) get_results_i() []IResult {
mut res := []IResult mut res := []IResult{}
for i in 0 .. pool.results.len { for i in 0 .. pool.results.len {
res << *(&IResult(pool.results[i])) res << *(&IResult(pool.results[i]))
} }

View File

@ -223,7 +223,7 @@ pub fn (mut v Builder) cc_msvc() {
v.pref.out_name += '.exe' v.pref.out_name += '.exe'
} }
v.pref.out_name = os.real_path(v.pref.out_name) 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 { if v.pref.build_mode == .build_module {
// Compile only // Compile only
a << '/c' a << '/c'

View File

@ -95,7 +95,7 @@ pub fn parse_file(path string, table &table.Table, comments_mode scanner.Comment
stmts << mstmt stmts << mstmt
// imports // imports
/* /*
mut imports := []ast.Import mut imports := []ast.Import{}
for p.tok.kind == .key_import { for p.tok.kind == .key_import {
imports << p.import_stmt() imports << p.import_stmt()
} }
@ -1102,7 +1102,7 @@ fn (mut p Parser) enum_decl() ast.EnumDecl {
name := p.prepend_mod(enum_name) name := p.prepend_mod(enum_name)
p.check(.lcbr) p.check(.lcbr)
mut vals := []string{} mut vals := []string{}
// mut default_exprs := []ast.Expr // mut default_exprs := []ast.Expr{}
mut fields := []ast.EnumField{} mut fields := []ast.EnumField{}
for p.tok.kind != .eof && p.tok.kind != .rcbr { for p.tok.kind != .eof && p.tok.kind != .rcbr {
pos := p.tok.position() pos := p.tok.position()

View File

@ -40,7 +40,7 @@ fn test_eval() {
start_pos: 0 start_pos: 0
parent: 0 parent: 0
} }
mut stmts := []ast.Stmt mut stmts := []ast.Stmt{}
for input in inputs { for input in inputs {
stmts << parse_stmt(input, table, scope) stmts << parse_stmt(input, table, scope)
} }
@ -103,7 +103,7 @@ fn test_one() {
start_pos: 0 start_pos: 0
parent: 0 parent: 0
} }
mut e := []ast.Stmt mut e := []ast.Stmt{}
for line in input { for line in input {
e << parse_stmt(line, table, scope) e << parse_stmt(line, table, scope)
} }
@ -194,7 +194,7 @@ fn test_parse_expr() {
'-a + 1;', '-a + 1;',
'2 + 2;', '2 + 2;',
] ]
mut e := []ast.Stmt mut e := []ast.Stmt{}
table := table.new_table() table := table.new_table()
vpref := &pref.Preferences{} vpref := &pref.Preferences{}
mut checker := checker.new_checker(table, vpref) mut checker := checker.new_checker(table, vpref)

View File

@ -8,7 +8,7 @@ import v.token
fn test_scan() { fn test_scan() {
text := 'println(2 + 3)' text := 'println(2 + 3)'
mut scanner := new_scanner(text, .skip_comments) mut scanner := new_scanner(text, .skip_comments)
mut token_kinds := []token.Kind mut token_kinds := []token.Kind{}
for { for {
tok := scanner.scan() tok := scanner.scan()
if tok.kind == .eof { if tok.kind == .eof {

View File

@ -134,7 +134,7 @@ fn test_anon_fn() {
println('hello from f1') println('hello from f1')
} }
f1(1) f1(1)
f2 := fn(a int) int { f2 := fn(a int) int {
println('hello from f2') println('hello from f2')
return 10 return 10
@ -171,7 +171,7 @@ struct MySt {
f MyFn f MyFn
} }
fn test_fn_type_call() { fn test_fn_type_call() {
mut arr := []MyFn mut arr := []MyFn{}
arr << MyFn(test) arr << MyFn(test)
// TODO: `arr[0](10)` // TODO: `arr[0](10)`
// assert arr[0](10) == 1010 // assert arr[0](10) == 1010
@ -185,4 +185,3 @@ fn test_fn_type_call() {
st1 := &MySt{f:test} st1 := &MySt{f:test}
assert st1.f(10) == 1010 assert st1.f(10) == 1010
} }

View File

@ -15,7 +15,7 @@ fn sum<T>(l []T) T {
} }
fn map_f<T,U>(l []T, f fn(T)U) []U { fn map_f<T,U>(l []T, f fn(T)U) []U {
mut r := []U mut r := []U{}
for e in l { for e in l {
r << f(e) r << f(e)
} }