diff --git a/vlib/v/checker/containers.v b/vlib/v/checker/containers.v index 792763162a..22be6ae946 100644 --- a/vlib/v/checker/containers.v +++ b/vlib/v/checker/containers.v @@ -188,6 +188,10 @@ fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type { continue } typ = c.check_expr_option_or_result_call(expr, c.expr(mut expr)) + sym := c.table.sym(expected_value_type) + if sym.kind == .interface { + c.type_implements(typ, expected_value_type, expr.pos()) + } } if expr is ast.CallExpr { ret_sym := c.table.sym(typ) diff --git a/vlib/v/markused/walker.v b/vlib/v/markused/walker.v index 62f1f2670e..bdf66037e2 100644 --- a/vlib/v/markused/walker.v +++ b/vlib/v/markused/walker.v @@ -697,7 +697,7 @@ fn (mut w Walker) expr(node_ ast.Expr) { .blank_ident {} else { // `.unresolved`, `.variable` - // println('>>> else, ast.Ident ${node.name} kind: $node.kind ') + // println('>>> else, ast.Ident ${node.name} kind: $node.kind ') if node.name in w.all_consts { w.mark_const_as_used(node.name) } else if node.name in w.all_globals { @@ -1447,6 +1447,7 @@ fn (mut w Walker) mark_resource_dependencies() { if w.uses_append { ref_array_idx_str := int(ast.array_type.ref()).str() w.fn_by_name(ref_array_idx_str + '.push') + w.fn_by_name(ref_array_idx_str + '.push_many') w.fn_by_name(ref_array_idx_str + '.push_many_noscan') w.fn_by_name(ref_array_idx_str + '.push_noscan') } diff --git a/vlib/v/tests/skip_unused/array_push_with_interface_array.run.out b/vlib/v/tests/skip_unused/array_push_with_interface_array.run.out new file mode 100644 index 0000000000..e440e5c842 --- /dev/null +++ b/vlib/v/tests/skip_unused/array_push_with_interface_array.run.out @@ -0,0 +1 @@ +3 \ No newline at end of file diff --git a/vlib/v/tests/skip_unused/array_push_with_interface_array.skip_unused.run.out b/vlib/v/tests/skip_unused/array_push_with_interface_array.skip_unused.run.out new file mode 100644 index 0000000000..e440e5c842 --- /dev/null +++ b/vlib/v/tests/skip_unused/array_push_with_interface_array.skip_unused.run.out @@ -0,0 +1 @@ +3 \ No newline at end of file diff --git a/vlib/v/tests/skip_unused/array_push_with_interface_array.vv b/vlib/v/tests/skip_unused/array_push_with_interface_array.vv new file mode 100644 index 0000000000..7cdc4c9d35 --- /dev/null +++ b/vlib/v/tests/skip_unused/array_push_with_interface_array.vv @@ -0,0 +1,7 @@ +interface Value {} + +fn main() { + mut a := []Value{} + a << [Value(i32(1)), 2, 3.0] + println(a.len) +}