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

cgen: fix nested array call (#11948)

This commit is contained in:
yuyi 2021-09-23 13:50:37 +08:00 committed by GitHub
parent 7b60367512
commit b8935551f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -167,6 +167,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.writeln('\t$inp_elem_type it = (($inp_elem_type*) ${tmp}_orig.data)[$i];')
g.stmt_path_pos << g.out.len
mut is_embed_map_filter := false
mut expr := node.args[0].expr
match mut expr {
@ -349,6 +350,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('\t$elem_type_str it = (($elem_type_str*) ${tmp}_orig.data)[$i];')
g.stmt_path_pos << g.out.len
mut is_embed_map_filter := false
mut expr := node.args[0].expr
match mut expr {
@ -631,6 +633,7 @@ fn (mut g Gen) gen_array_any(node ast.CallExpr) {
i := g.new_tmp_var()
g.writeln('for (int $i = 0; $i < ${tmp}_len; ++$i) {')
g.writeln('\t$elem_type_str it = (($elem_type_str*) ${tmp}_orig.data)[$i];')
g.stmt_path_pos << g.out.len
mut is_embed_map_filter := false
mut expr := node.args[0].expr
match mut expr {
@ -704,6 +707,7 @@ fn (mut g Gen) gen_array_all(node ast.CallExpr) {
i := g.new_tmp_var()
g.writeln('for (int $i = 0; $i < ${tmp}_len; ++$i) {')
g.writeln('\t$elem_type_str it = (($elem_type_str*) ${tmp}_orig.data)[$i];')
g.stmt_path_pos << g.out.len
mut is_embed_map_filter := false
mut expr := node.args[0].expr
match mut expr {

View File

@ -0,0 +1,6 @@
fn test_array_nested_call() {
arr := ['abc', 'def']
all_is_letter := arr.all(it.bytes().all(it.is_letter()))
println(all_is_letter)
assert all_is_letter
}