1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: fix remaining []array warnings

This commit is contained in:
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 {
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]

View File

@ -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()

View File

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

View File

@ -4,7 +4,7 @@ const (
)
fn test_pointer() {
mut arr := []&int
mut arr := []&int{}
a := 1
b := 2
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 {
arr := array {
len: mylen
@ -130,6 +130,5 @@ pub fn (arr mut array) push_many(val voidptr, size int) {
}
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 {
mut atoms := []C.Atom
mut atoms := []C.Atom{}
for typ in types {
atoms << cb.atoms[typ]
}

View File

@ -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
}

View File

@ -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"

View File

@ -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 := ''

View File

@ -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()

View File

@ -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 {

View File

@ -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

View File

@ -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 {

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)
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
}

View File

@ -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>() []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]))
}

View File

@ -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'

View File

@ -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()

View File

@ -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)

View File

@ -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 {

View File

@ -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
}

View File

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