cgen: fix filter in map (#7844)

pull/7853/head
Daniel Däschle 2021-01-04 01:04:53 +01:00 committed by GitHub
parent baae302894
commit 43adbf4b66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -149,6 +149,7 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) {
i := g.new_tmp_var()
g.writeln('for (int $i = 0; $i < ${tmp}_len; ++$i) {')
g.write('\t$inp_elem_type it = (($inp_elem_type*) ${tmp}_orig.data)[$i];')
g.stmt_path_pos << g.out.len
g.write('\t$ret_elem_type ti = ')
expr := node.args[0].expr
match expr {
@ -302,6 +303,7 @@ fn (mut g Gen) gen_array_filter(node ast.CallExpr) {
i := g.new_tmp_var()
g.writeln('for (int $i = 0; $i < ${tmp}_len; ++$i) {')
g.writeln(' $elem_type_str it = (($elem_type_str*) ${tmp}_orig.data)[$i];')
g.stmt_path_pos << g.out.len
g.write('if (')
expr := node.args[0].expr
match expr {

View File

@ -0,0 +1,5 @@
fn filter_in_map_test() {
x := [['']]
y := x.map(it.filter(it != ''))
assert y[0].len == 0
}