Skip to content

Commit

Permalink
checker: fix generic fn with nested generic fn call (fix #18285) (#18314
Browse files Browse the repository at this point in the history
)
  • Loading branch information
yuyi98 committed Jun 2, 2023
1 parent a647a71 commit 5e12d34
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
22 changes: 16 additions & 6 deletions vlib/v/checker/fn.v
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions vlib/v/tests/generic_fn_with_nested_generic_fn_call_test.v
@@ -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
}

0 comments on commit 5e12d34

Please sign in to comment.