From 4a833d8151d9c4968e1a52c70266f589c3560339 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 14 Nov 2019 09:18:07 +0300 Subject: [PATCH] parser: clean up all [] --- vlib/builtin/string.v | 2 +- vlib/compiler/fn.v | 16 +++++++++------- vlib/compiler/main.v | 2 +- vlib/compiler/parser.v | 8 ++++++-- vlib/compiler/query.v | 5 +++-- vlib/os/os.v | 2 +- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 80e6cf41ce..9d3e24aab9 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -1117,7 +1117,7 @@ pub fn (s string) hash() int { pub fn (s string) bytes() []byte { if s.len == 0 { - return []byte + return [] } mut buf := [byte(0)].repeat(s.len) C.memcpy(buf.data, s.str, s.len) diff --git a/vlib/compiler/fn.v b/vlib/compiler/fn.v index 9452aa1ae3..f538f5a7ac 100644 --- a/vlib/compiler/fn.v +++ b/vlib/compiler/fn.v @@ -171,7 +171,7 @@ fn (p mut Parser) clear_vars() { if p.pref.autofree { //p.local_vars.free() } - p.local_vars = []Var + p.local_vars = [] } } @@ -1408,7 +1408,8 @@ fn (p mut Parser) dispatch_generic_fn_instance(f mut Fn, ti TypeInst) { f.args = _f.args f.typ = _f.typ f.is_generic = false - f.type_inst = []TypeInst + f.type_inst = [] + if false {} f.dispatch_of = ti // println('using existing inst $f.name(${f.str_args(p.table)}) $f.typ') return @@ -1431,17 +1432,18 @@ fn (p mut Parser) dispatch_generic_fn_instance(f mut Fn, ti TypeInst) { p.rename_generic_fn_instance(mut f, ti) f.is_generic = false // the instance is a normal function - f.type_inst = []TypeInst + f.type_inst = [] + if false {} f.scope_level = 0 f.dispatch_of = ti // TODO this is done to prevent a crash as a result of this not being // properly initialised. This is a bug somewhere futher upstream - f.defer_text = []string - + f.defer_text = [] + if false {} old_args := f.args new_types := p.replace_type_params(f, ti) - f.args = []Var + f.args = [] for i in 0..new_types.len-1 { mut v := old_args[i] v.typ = new_types[i] @@ -1465,7 +1467,7 @@ fn (p mut Parser) dispatch_generic_fn_instance(f mut Fn, ti TypeInst) { p.returns = false p.cgen.tmp_line = '' p.cgen.cur_line = '' - p.cgen.lines = []string + p.cgen.lines = [] unsafe { // TODO p.cur_fn = *f } diff --git a/vlib/compiler/main.v b/vlib/compiler/main.v index dc527c066f..0b047a1400 100644 --- a/vlib/compiler/main.v +++ b/vlib/compiler/main.v @@ -570,7 +570,7 @@ pub fn (v &V) v_files_from_dir(dir string) []string { pub fn (v mut V) add_v_files_to_compile() { mut builtin_files := v.get_builtin_files() if v.pref.is_bare { - builtin_files = []string + builtin_files = [] } // Builtin cache exists? Use it. builtin_vh := '$v_modules_path${os.path_separator}vlib${os.path_separator}builtin.vh' diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index e8cfb824a4..90091a715c 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -2424,13 +2424,17 @@ fn (p mut Parser) array_init() string { } p.check(.rsbr) // type after `]`? (e.g. "[]string") - if p.tok != .name && i == 0 && !p.expected_type.starts_with('array_') { + exp_array := p.expected_type.starts_with('array_') + if p.tok != .name && i == 0 && !exp_array { p.error('specify array type: `[]typ` instead of `[]`') } if p.tok == .name && i == 0 { // vals.len == 0 { + if exp_array { + p.error('use `foo = []` instead of `foo = []Type`') + } typ = p.get_type() - } else if p.expected_type.starts_with('array_') { + } else if exp_array { // allow `known_array = []` typ = p.expected_type[6..] } diff --git a/vlib/compiler/query.v b/vlib/compiler/query.v index ba6ae39d6b..ba7c132928 100644 --- a/vlib/compiler/query.v +++ b/vlib/compiler/query.v @@ -38,8 +38,9 @@ fn (p mut Parser) select_query(fn_ph int) string { // because we can have many queries in the _same_ scope. qprefix := p.get_tmp().replace('tmp','sql') + '_' p.sql_i = 0 - p.sql_params = []string - p.sql_types = []string + p.sql_params = [] + if false {} + p.sql_types = [] mut q := 'select ' p.check(.key_select) diff --git a/vlib/os/os.v b/vlib/os/os.v index a44a6b498d..821a9159a9 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -852,7 +852,7 @@ pub fn realpath(fpath string) string { // walk_ext returns a recursive list of all file paths ending with `ext`. pub fn walk_ext(path, ext string) []string { if !os.is_dir(path) { - return []string + return [] } mut files := os.ls(path) or { panic(err) } mut res := []string