mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
markused: fix for generic ptr receiver on method call (fix #24555) (#24558)
This commit is contained in:
parent
ca379439fb
commit
eebfa1ba6b
2 changed files with 54 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
49
vlib/v/tests/generics/generic_different_type_test.v
Normal file
49
vlib/v/tests/generics/generic_different_type_test.v
Normal file
|
@ -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()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue