From cb2e4dd7eee9d524cd1cce32a108747f770a2a29 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 14 Apr 2026 12:45:26 +0300 Subject: [PATCH] checker: Test vlib/v/tests/aliases/modules/value/value_test.v failed in a single file (fixes #26103) --- vlib/v/checker/containers.v | 11 +++++++--- .../alias_array_returned_as_interface_test.v | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 vlib/v/tests/aliases/alias_array_returned_as_interface_test.v diff --git a/vlib/v/checker/containers.v b/vlib/v/checker/containers.v index 4dfab0d6c..db40dfa0a 100644 --- a/vlib/v/checker/containers.v +++ b/vlib/v/checker/containers.v @@ -5,6 +5,11 @@ module checker import v.ast import v.token +@[inline] +fn array_init_result_type(node ast.ArrayInit) ast.Type { + return if node.alias_type != ast.void_type { node.alias_type } else { node.typ } +} + fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type { $if trace_ci_fixes ? { if c.table.cur_fn != unsafe { nil } && c.table.cur_concrete_types.len > 0 @@ -210,10 +215,10 @@ fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type { if node.typ.has_flag(.generic) && c.table.cur_fn != unsafe { nil } { resolved := c.recheck_concrete_type(node.typ) if resolved != node.typ && !resolved.has_flag(.generic) { - return resolved + return if node.alias_type != ast.void_type { node.alias_type } else { resolved } } } - return node.typ + return array_init_result_type(node) } if node.is_fixed { @@ -401,7 +406,7 @@ fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type { c.check_array_init_default_expr(mut node) } } - return node.typ + return array_init_result_type(node) } fn (mut c Checker) check_array_init_default_expr(mut node ast.ArrayInit) { diff --git a/vlib/v/tests/aliases/alias_array_returned_as_interface_test.v b/vlib/v/tests/aliases/alias_array_returned_as_interface_test.v new file mode 100644 index 000000000..1a8a0b4d5 --- /dev/null +++ b/vlib/v/tests/aliases/alias_array_returned_as_interface_test.v @@ -0,0 +1,21 @@ +module main + +interface Value { + str() string +} + +type List = []Value + +fn (x List) str() string { + return x.str() +} + +fn make_list() !Value { + mut list := List{} + return list +} + +fn test_alias_array_returned_as_interface() { + mut list := make_list()! + assert (list as List).len == 0 +} -- 2.39.5