diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 2ef862e65c..097ceacb3a 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -1799,7 +1799,12 @@ pub fn (mut t Table) generic_type_names(generic_type Type) []string { } Struct, Interface, SumType { if sym.info.is_generic { - names << sym.info.generic_types.map(t.sym(it).name) + if sym.generic_types.len > 0 { + // Foo[U] (declaration: Foo[T]) + names << sym.generic_types.map(t.sym(it).name) + } else { + names << sym.info.generic_types.map(t.sym(it).name) + } } } else {} diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 24d6917fee..c86af5079f 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -131,10 +131,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) { c.error('fixed array cannot be returned by function', node.return_type_pos) } // Ensure each generic type of the parameter was declared in the function's definition - // TODO: fix inconsistent return_type type case - if node.return_type.has_flag(.generic) && (return_sym.kind == .any - || (return_sym.kind == .array - && c.table.sym((return_sym.info as ast.Array).elem_type).kind == .any)) { + if node.return_type.has_flag(.generic) { generic_names := c.table.generic_type_names(node.return_type) for name in generic_names { if name !in node.generic_names {