markused: fix for generic ptr receiver on method call (fix #24555) (#24558)

This commit is contained in:
Felipe Pena 2025-05-25 07:18:09 -03:00 committed by GitHub
parent ca379439fb
commit eebfa1ba6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 54 additions and 1 deletions

View file

@ -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 c.table.used_features.comptime_calls['${int(left_type)}.${node.name}'] = true
} }
} else if left_type.has_flag(.generic) { } 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
}
} }
} }

View 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()
}