Skip to content

Commit af62364

Browse files
authored
checker: maintain correct ref level in generic fn (fix #25676) (#25687)
1 parent 8002234 commit af62364

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

vlib/v/checker/check_types.v

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,13 @@ fn (mut c Checker) infer_fn_generic_types(func &ast.Fn, mut node ast.CallExpr) {
10671067
}
10681068
// resolve &T &&T ...
10691069
if param.typ.nr_muls() > 0 && typ.nr_muls() > 0 {
1070-
typ = typ.set_nr_muls(0)
1070+
param_muls := param.typ.nr_muls()
1071+
arg_muls := typ.nr_muls()
1072+
typ = if arg_muls >= param_muls {
1073+
typ.set_nr_muls(arg_muls - param_muls)
1074+
} else {
1075+
typ.set_nr_muls(0)
1076+
}
10711077
}
10721078
} else if param.typ.has_flag(.generic) {
10731079
arg_typ := if c.table.sym(arg.typ).kind == .any {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn foo[T](v &T) string {
2+
return typeof(v).name
3+
}
4+
5+
fn test_main() {
6+
i := i8(0)
7+
ip := &i
8+
ipp := &ip
9+
assert foo(ip) == '&i8'
10+
assert foo(ipp) == '&&i8'
11+
}

0 commit comments

Comments
 (0)