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

update []

This commit is contained in:
Alexander Medvednikov 2019-11-14 09:53:05 +03:00
parent 4a833d8151
commit 96b530cf85
7 changed files with 41 additions and 40 deletions

View File

@ -65,12 +65,12 @@ struct K {
}
fn test_empty() {
mut chunks := []Chunk
mut chunks := []
a := Chunk{}
assert chunks.len == 0
chunks << a
assert chunks.len == 1
chunks = []Chunk
chunks = []
assert chunks.len == 0
chunks << a
assert chunks.len == 1

View File

@ -2428,13 +2428,14 @@ fn (p mut Parser) array_init() string {
if p.tok != .name && i == 0 && !exp_array {
p.error('specify array type: `[]typ` instead of `[]`')
}
if p.tok == .name && i == 0 {
if p.tok == .name && i == 0 &&
p.tokens[p.token_idx-2].line_nr == p.tokens[p.token_idx-1].line_nr { // TODO
// vals.len == 0 {
if exp_array {
p.error('use `foo = []` instead of `foo = []Type`')
}
typ = p.get_type()
} else if exp_array {
} else if exp_array && i == 0 {
// allow `known_array = []`
typ = p.expected_type[6..]
}

View File

@ -67,7 +67,7 @@ pub fn (d mut Digest) write(p_ []byte) int {
d.nx = 0
}
if n >= p.len {
p = []byte
p = []
} else {
p = p[n..]
}
@ -76,7 +76,7 @@ pub fn (d mut Digest) write(p_ []byte) int {
n := p.len &~ (block_size - 1)
block(mut d, p[..n])
if n >= p.len {
p = []byte
p = []
} else {
p = p[n..]
}

View File

@ -71,7 +71,7 @@ pub fn (d mut Digest) write(p_ []byte) int {
d.nx = 0
}
if n >= p.len {
p = []byte
p = []
} else {
p = p[n..]
}
@ -80,7 +80,7 @@ pub fn (d mut Digest) write(p_ []byte) int {
n := p.len &~ (chunk - 1)
block(d, p[..n])
if n >= p.len {
p = []byte
p = []
} else {
p = p[n..]
}

View File

@ -163,7 +163,7 @@ fn (d mut Digest) write(p_ []byte) int {
d.nx = 0
}
if n >= p.len {
p = []byte
p = []
} else {
p = p[n..]
}
@ -172,7 +172,7 @@ fn (d mut Digest) write(p_ []byte) int {
n := p.len &~ (Chunk - 1)
block(mut d, p[..n])
if n >= p.len {
p = []byte
p = []
} else {
p = p[n..]
}

View File

@ -2,7 +2,7 @@
import flag
fn test_if_flag_not_given_return_default_values() {
mut fp := flag.new_flag_parser([]string)
mut fp := flag.new_flag_parser([])
assert false == fp.bool('a_bool', false, '')
&& 42 == fp.int('an_int', 42, '')
@ -12,7 +12,7 @@ fn test_if_flag_not_given_return_default_values() {
fn test_could_define_application_name_and_version() {
mut fp := flag.new_flag_parser([]string)
mut fp := flag.new_flag_parser([])
fp.application('test app')
fp.version('0.0.42')
fp.description('some text')

View File

@ -53,11 +53,11 @@ pub fn (v &Values) get(key string) string {
// a empty []string.
pub fn (v &Values) get_all(key string) []string {
if v.data.size == 0 {
return []string
return []
}
vs := v.data[key]
if vs.data.len == 0 {
return []string
return []
}
return vs.data
}
@ -76,7 +76,7 @@ pub fn (v mut Values) set(key, value string) {
pub fn (v mut Values) add(key, value string) {
mut a := v.data[key]
if a.data.len == 0 {
a.data = []string
a.data = []
}
a.data << value
v.data[key] = a