diff --git a/vlib/v/checker/used_features.v b/vlib/v/checker/used_features.v index 99704135b3..287733a6fa 100644 --- a/vlib/v/checker/used_features.v +++ b/vlib/v/checker/used_features.v @@ -151,7 +151,11 @@ fn (mut c Checker) markused_method_call(mut node ast.CallExpr, mut left_expr ast c.table.used_features.comptime_calls['${int(left_type)}.${node.name}'] = true } } else if left_type.has_flag(.generic) { - c.table.used_features.comptime_calls['${int(c.unwrap_generic(left_type))}.${node.name}'] = true + unwrapped_left := c.unwrap_generic(left_type) + c.table.used_features.comptime_calls['${int(unwrapped_left)}.${node.name}'] = true + if !unwrapped_left.is_ptr() && left_expr is ast.Ident && left_expr.is_mut() { + c.table.used_features.comptime_calls['${int(unwrapped_left.ref())}.${node.name}'] = true + } } } diff --git a/vlib/v/tests/generics/generic_different_type_test.v b/vlib/v/tests/generics/generic_different_type_test.v new file mode 100644 index 0000000000..d03d94ce2e --- /dev/null +++ b/vlib/v/tests/generics/generic_different_type_test.v @@ -0,0 +1,49 @@ +module main + +struct DBFoo {} + +struct DBFoo2 {} + +struct ConnectionPoolGeneric[T] { +mut: + connections chan T +} + +fn (mut f DBFoo) close() {} + +fn (mut f DBFoo2) close() {} + +pub fn new_conn_pool[T](size int) !&ConnectionPoolGeneric[T] { + $if T is DBFoo2 { + mut pool := &ConnectionPoolGeneric[DBFoo2]{ + connections: chan DBFoo2{cap: size} + } + return pool + } $else { + return error('') + } +} + +pub fn (mut pool ConnectionPoolGeneric[T]) acquire() !T { + conn := <-pool.connections or { return error('Failed mysql') } + return conn +} + +pub fn (mut pool ConnectionPoolGeneric[T]) release(conn T) { + pool.connections <- conn +} + +pub fn (mut pool ConnectionPoolGeneric[T]) close() { + for _ in 0 .. pool.connections.len { + mut conn := <-pool.connections or { break } + conn.close() + } +} + +fn test_main() { + mut pool := new_conn_pool[DBFoo](5) or { + assert true + return + } + pool.close() +}