array: fix map() return type and handle []bool

pull/2558/head
Alexander Medvednikov 2019-10-26 14:49:36 +03:00
parent f40d672a12
commit 70c9565607
3 changed files with 23 additions and 3 deletions

View File

@ -259,6 +259,26 @@ pub fn (a []string) str() string {
return sb.str() return sb.str()
} }
// "[true, true, false]"
pub fn (a []bool) str() string {
mut sb := strings.new_builder(a.len * 3)
sb.write('[')
for i := 0; i < a.len; i++ {
val := a[i]
if val {
sb.write('true')
} else {
sb.write('false')
}
if i < a.len - 1 {
sb.write(', ')
}
}
sb.write(']')
return sb.str()
}
pub fn (b []byte) hex() string { pub fn (b []byte) hex() string {
mut hex := malloc(b.len*2+1) mut hex := malloc(b.len*2+1)
mut ptr := &hex[0] mut ptr := &hex[0]

View File

@ -375,7 +375,7 @@ fn (p mut Parser) gen_array_filter(str_typ string, method_ph int) {
p.close_scope() p.close_scope()
} }
fn (p mut Parser) gen_array_map(str_typ string, method_ph int) { fn (p mut Parser) gen_array_map(str_typ string, method_ph int) string {
/* /*
// V // V
a := [1,2,3,4] a := [1,2,3,4]
@ -412,4 +412,5 @@ fn (p mut Parser) gen_array_map(str_typ string, method_ph int) {
p.gen(tmp) // TODO why does this `gen()` work? p.gen(tmp) // TODO why does this `gen()` work?
p.check(.rpar) p.check(.rpar)
p.close_scope() p.close_scope()
return 'array_' + map_type
} }

View File

@ -1948,8 +1948,7 @@ fn (p mut Parser) dot(str_typ_ string, method_ph int) string {
return str_typ return str_typ
} }
else if field_name == 'map' && str_typ.starts_with('array_') { else if field_name == 'map' && str_typ.starts_with('array_') {
p.gen_array_map(str_typ, method_ph) return p.gen_array_map(str_typ, method_ph)
return str_typ
} }
fname_tidx := p.cur_tok_index() fname_tidx := p.cur_tok_index()