mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
parent
927ec1fadb
commit
0bf23488dc
6 changed files with 81 additions and 13 deletions
|
@ -171,9 +171,9 @@ fn (mut ws Client) send_message_event(msg &Message) {
|
||||||
ws.debug_log('sending on_message event')
|
ws.debug_log('sending on_message event')
|
||||||
for ev_handler in ws.message_callbacks {
|
for ev_handler in ws.message_callbacks {
|
||||||
if !ev_handler.is_ref {
|
if !ev_handler.is_ref {
|
||||||
ev_handler.handler(ws, msg) or { ws.logger.error('send_message_event error: $err') }
|
ev_handler.handler(mut ws, msg) or { ws.logger.error('send_message_event error: $err') }
|
||||||
} else {
|
} else {
|
||||||
ev_handler.handler2(ws, msg, ev_handler.ref) or {
|
ev_handler.handler2(mut ws, msg, ev_handler.ref) or {
|
||||||
ws.logger.error('send_message_event error: $err')
|
ws.logger.error('send_message_event error: $err')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,14 +66,14 @@ struct Picoev {
|
||||||
loop &C.picoev_loop
|
loop &C.picoev_loop
|
||||||
cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response)
|
cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response)
|
||||||
err_cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response, IError)
|
err_cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response, IError)
|
||||||
user_data voidptr
|
|
||||||
timeout_secs int
|
timeout_secs int
|
||||||
max_headers int
|
max_headers int
|
||||||
mut:
|
mut:
|
||||||
date &u8
|
user_data voidptr
|
||||||
buf &u8
|
date &u8
|
||||||
idx [1024]int
|
buf &u8
|
||||||
out &u8
|
idx [1024]int
|
||||||
|
out &u8
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
|
@ -158,20 +158,20 @@ fn rw_callback(loop &C.picoev_loop, fd int, events int, context voidptr) {
|
||||||
if pret > 0 { // Success
|
if pret > 0 { // Success
|
||||||
break
|
break
|
||||||
} else if pret == -1 { // Parse error
|
} else if pret == -1 { // Parse error
|
||||||
p.err_cb(mut p.user_data, req, mut &res, error('ParseError'))
|
p.err_cb(p.user_data, req, mut &res, error('ParseError'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
assert pret == -2
|
assert pret == -2
|
||||||
// request is incomplete, continue the loop
|
// request is incomplete, continue the loop
|
||||||
if p.idx[fd] == sizeof(buf) {
|
if p.idx[fd] == sizeof(buf) {
|
||||||
p.err_cb(mut p.user_data, req, mut &res, error('RequestIsTooLongError'))
|
p.err_cb(p.user_data, req, mut &res, error('RequestIsTooLongError'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback (should call .end() itself)
|
// Callback (should call .end() itself)
|
||||||
p.cb(mut p.user_data, req, mut &res)
|
p.cb(p.user_data, req, mut &res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ fn accept_callback(loop &C.picoev_loop, fd int, events int, cb_arg voidptr) {
|
||||||
newfd := C.accept(fd, 0, 0)
|
newfd := C.accept(fd, 0, 0)
|
||||||
if newfd != -1 {
|
if newfd != -1 {
|
||||||
setup_sock(newfd) or {
|
setup_sock(newfd) or {
|
||||||
p.err_cb(mut p.user_data, picohttpparser.Request{}, mut &picohttpparser.Response{},
|
p.err_cb(p.user_data, picohttpparser.Request{}, mut &picohttpparser.Response{},
|
||||||
err)
|
err)
|
||||||
}
|
}
|
||||||
C.picoev_add(voidptr(loop), newfd, int(Event.read), p.timeout_secs, rw_callback,
|
C.picoev_add(voidptr(loop), newfd, int(Event.read), p.timeout_secs, rw_callback,
|
||||||
|
@ -221,7 +221,7 @@ pub fn new(config Config) &Picoev {
|
||||||
listen_res := C.listen(fd, C.SOMAXCONN)
|
listen_res := C.listen(fd, C.SOMAXCONN)
|
||||||
assert listen_res == 0
|
assert listen_res == 0
|
||||||
setup_sock(fd) or {
|
setup_sock(fd) or {
|
||||||
config.err_cb(mut config.user_data, picohttpparser.Request{}, mut &picohttpparser.Response{},
|
config.err_cb(config.user_data, picohttpparser.Request{}, mut &picohttpparser.Response{},
|
||||||
err)
|
err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1595,6 +1595,42 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
|
||||||
arg.typ = targ
|
arg.typ = targ
|
||||||
earg_types << targ
|
earg_types << targ
|
||||||
|
|
||||||
|
param := if info.func.is_variadic && i >= info.func.params.len - 1 {
|
||||||
|
info.func.params.last()
|
||||||
|
} else {
|
||||||
|
info.func.params[i]
|
||||||
|
}
|
||||||
|
param_share := param.typ.share()
|
||||||
|
if param_share == .shared_t && (c.locked_names.len > 0 || c.rlocked_names.len > 0) {
|
||||||
|
c.error('method with `shared` arguments cannot be called inside `lock`/`rlock` block',
|
||||||
|
arg.pos)
|
||||||
|
}
|
||||||
|
if arg.is_mut {
|
||||||
|
to_lock, pos := c.fail_if_immutable(arg.expr)
|
||||||
|
if !param.is_mut {
|
||||||
|
tok := arg.share.str()
|
||||||
|
c.error('`$node.name` parameter `$param.name` is not `$tok`, `$tok` is not needed`',
|
||||||
|
arg.expr.pos())
|
||||||
|
} else {
|
||||||
|
if param_share != arg.share {
|
||||||
|
c.error('wrong shared type `$arg.share.str()`, expected: `$param_share.str()`',
|
||||||
|
arg.expr.pos())
|
||||||
|
}
|
||||||
|
if to_lock != '' && param_share != .shared_t {
|
||||||
|
c.error('$to_lock is `shared` and must be `lock`ed to be passed as `mut`',
|
||||||
|
pos)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if param.is_mut {
|
||||||
|
tok := arg.share.str()
|
||||||
|
c.error('method `$node.name` parameter `$param.name` is `$tok`, so use `$tok $arg.expr` instead',
|
||||||
|
arg.expr.pos())
|
||||||
|
} else {
|
||||||
|
c.fail_if_unreadable(arg.expr, targ, 'argument')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if i < info.func.params.len {
|
if i < info.func.params.len {
|
||||||
exp_arg_typ := info.func.params[i].typ
|
exp_arg_typ := info.func.params[i].typ
|
||||||
c.check_expected_call_arg(targ, c.unwrap_generic(exp_arg_typ), node.language,
|
c.check_expected_call_arg(targ, c.unwrap_generic(exp_arg_typ), node.language,
|
||||||
|
|
6
vlib/v/checker/tests/method_call_arg_no_mut_err.out
Normal file
6
vlib/v/checker/tests/method_call_arg_no_mut_err.out
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/checker/tests/method_call_arg_no_mut_err.vv:25:14: error: method `alarm_fkt` parameter `a` is `mut`, so use `mut last` instead
|
||||||
|
23 | c.arr << Alarm{}
|
||||||
|
24 | mut last := c.arr.last()
|
||||||
|
25 | c.alarm_fkt(last)
|
||||||
|
| ~~~~
|
||||||
|
26 | }
|
26
vlib/v/checker/tests/method_call_arg_no_mut_err.vv
Normal file
26
vlib/v/checker/tests/method_call_arg_no_mut_err.vv
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
module main
|
||||||
|
|
||||||
|
type Fkt = fn (mut a Alarm)
|
||||||
|
|
||||||
|
struct Alarm {
|
||||||
|
x int
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Clock {
|
||||||
|
mut:
|
||||||
|
arr []Alarm
|
||||||
|
alarm_fkt Fkt
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fkt(mut a Alarm) {
|
||||||
|
println(a.x)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
mut c := Clock{
|
||||||
|
alarm_fkt: fkt
|
||||||
|
}
|
||||||
|
c.arr << Alarm{}
|
||||||
|
mut last := c.arr.last()
|
||||||
|
c.alarm_fkt(last)
|
||||||
|
}
|
|
@ -2224,7 +2224,7 @@ pub fn (mut g Gen) builtin_decl_amd64(builtin BuiltinFn) {
|
||||||
local_alloc_pos := g.pos()
|
local_alloc_pos := g.pos()
|
||||||
g.sub(.rsp, 0)
|
g.sub(.rsp, 0)
|
||||||
|
|
||||||
builtin.body(builtin, g)
|
builtin.body(builtin, mut g)
|
||||||
g.println('; stack frame size: $g.stack_var_pos')
|
g.println('; stack frame size: $g.stack_var_pos')
|
||||||
g.write32_at(local_alloc_pos + 3, g.stack_var_pos)
|
g.write32_at(local_alloc_pos + 3, g.stack_var_pos)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue