mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ast, checker: fix checking generic struct type mismatch (#16701)
This commit is contained in:
parent
9f1239c56e
commit
ba07e48691
@ -1799,7 +1799,12 @@ pub fn (mut t Table) generic_type_names(generic_type Type) []string {
|
|||||||
}
|
}
|
||||||
Struct, Interface, SumType {
|
Struct, Interface, SumType {
|
||||||
if sym.info.is_generic {
|
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 {}
|
else {}
|
||||||
|
@ -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)
|
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
|
// 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) {
|
||||||
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)) {
|
|
||||||
generic_names := c.table.generic_type_names(node.return_type)
|
generic_names := c.table.generic_type_names(node.return_type)
|
||||||
for name in generic_names {
|
for name in generic_names {
|
||||||
if name !in node.generic_names {
|
if name !in node.generic_names {
|
||||||
|
Loading…
Reference in New Issue
Block a user