checker: fix `instance.cb_field(mut arg)`
parent
1c6fe83408
commit
263fb7d7a8
|
@ -1534,10 +1534,13 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type {
|
|||
call_expr.is_field = true
|
||||
info := field_type_sym.info as table.FnType
|
||||
call_expr.return_type = info.func.return_type
|
||||
// TODO: check args (do it once for all of the above)
|
||||
for arg in call_expr.args {
|
||||
c.expr(arg.expr)
|
||||
mut earg_types := []table.Type{}
|
||||
for mut arg in call_expr.args {
|
||||
targ := c.expr(arg.expr)
|
||||
arg.typ = targ
|
||||
earg_types << targ
|
||||
}
|
||||
call_expr.expected_arg_types = earg_types
|
||||
return info.func.return_type
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
type Async_cb = fn (x []byte, mut y []byte) int
|
||||
|
||||
fn async_cb(b []byte, mut res []byte) int {
|
||||
if b.len > 0 {
|
||||
res << b
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
struct Ep_arg {
|
||||
mut:
|
||||
sfd int
|
||||
cb Async_cb
|
||||
}
|
||||
|
||||
fn test_struct_fn_field_can_be_used_directly() {
|
||||
buf := [byte(1), 2, 3]
|
||||
mut res := []byte{}
|
||||
res << 0x88
|
||||
async_cb(buf[0..2], mut res)
|
||||
data := Ep_arg{
|
||||
sfd: 1234
|
||||
cb: async_cb
|
||||
}
|
||||
data.cb(buf[1..2], mut res)
|
||||
res << 0x99
|
||||
eprintln(res)
|
||||
assert res == [byte(0x88), 0x01, 0x02, 0x02, 0x99]
|
||||
}
|
Loading…
Reference in New Issue