Skip to content

Commit d463817

Browse files
committed
Revert "Revert "cgen: fix generics with generics fn type parameter (#10078)""
This reverts commit d3de91e.
1 parent c55549a commit d463817

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

vlib/v/gen/c/cgen.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,7 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
23732373
}
23742374
else {}
23752375
}
2376-
right_sym := g.table.get_type_symbol(val_type)
2376+
right_sym := g.table.get_type_symbol(g.unwrap_generic(val_type))
23772377
is_fixed_array_copy := right_sym.kind == .array_fixed && val is ast.Ident
23782378
g.is_assign_lhs = true
23792379
g.assign_op = assign_stmt.op

vlib/v/tests/generics_with_generics_fn_type_parameter_test.v

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,40 @@ fn neg(a int) int {
44

55
fn indirect_call(func fn (int) int, a int) int {
66
println(typeof(func).name)
7+
assert typeof(func).name == typeof(neg).name
78
return func(a)
89
}
910

1011
fn generic_call<T>(func T, a int) int {
1112
println(T.name)
13+
assert T.name == typeof(neg).name
1214
return func(a)
1315
}
1416

1517
fn generic_indirect_call<T>(func T, a int) int {
1618
println(T.name)
19+
assert T.name == typeof(neg).name
1720
return indirect_call(func, a)
1821
}
1922

23+
fn indirect_call_v2(func fn (int) int, a int) int {
24+
f := func
25+
assert typeof(f).name == typeof(neg).name
26+
return f(a)
27+
}
28+
29+
fn generic_call_v2<T>(func T, a int) int {
30+
f := func
31+
assert typeof(f).name == typeof(neg).name
32+
return f(a)
33+
}
34+
35+
fn generic_indirect_call_v2<T>(func T, a int) int {
36+
f := func
37+
assert typeof(f).name == typeof(neg).name
38+
return indirect_call_v2(f, a)
39+
}
40+
2041
fn test_generics_with_generics_fn_type_parameter() {
2142
mut ret := 0
2243

@@ -31,4 +52,16 @@ fn test_generics_with_generics_fn_type_parameter() {
3152
ret = generic_indirect_call(neg, 4)
3253
println(ret)
3354
assert ret == -4
55+
56+
ret = indirect_call_v2(neg, 5)
57+
println(ret)
58+
assert ret == -5
59+
60+
ret = generic_call_v2(neg, 6)
61+
println(ret)
62+
assert ret == -6
63+
64+
ret = generic_indirect_call_v2(neg, 7)
65+
println(ret)
66+
assert ret == -7
3467
}

0 commit comments

Comments
 (0)