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

checker: fix generic fn with nested generic fn call (fix #18285) (#18314)

This commit is contained in:
yuyi 2023-06-02 15:52:29 +08:00 committed by GitHub
parent a647a71c52
commit 5e12d3483c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 6 deletions

View File

@ -1354,13 +1354,23 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
}
}
return node.return_type
} else if typ := c.table.resolve_generic_to_concrete(func.return_type, func.generic_names,
concrete_types)
{
if typ.has_flag(.generic) {
node.return_type = typ
} else {
if node.concrete_types.len > 0 && !node.concrete_types.any(it.has_flag(.generic)) {
if typ := c.table.resolve_generic_to_concrete(func.return_type, func.generic_names,
node.concrete_types)
{
node.return_type = typ
return typ
}
}
if typ := c.table.resolve_generic_to_concrete(func.return_type, func.generic_names,
concrete_types)
{
if typ.has_flag(.generic) {
node.return_type = typ
}
return typ
}
return typ
}
}
return func.return_type

View File

@ -0,0 +1,14 @@
struct Test {}
fn unmarshal[T]() ! {
get_number[int]()!
}
fn get_number[T]() !T {
return T(42)
}
fn test_generic_fn_with_nested_generic_fn_call() {
unmarshal[Test]()!
assert true
}