mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
6756d28595
commit
dd0b68ac90
@ -37,11 +37,11 @@ fn main() {
|
|||||||
// someone is trying to connect
|
// someone is trying to connect
|
||||||
eprint('trying to connect.. ')
|
eprint('trying to connect.. ')
|
||||||
if conn := listener.accept() {
|
if conn := listener.accept() {
|
||||||
if _ := notifier.add(conn.sock.handle, .read | .peer_hangup) {
|
notifier.add(conn.sock.handle, .read | .peer_hangup) or {
|
||||||
eprintln('connected')
|
|
||||||
} else {
|
|
||||||
eprintln('error adding to notifier: ${err}')
|
eprintln('error adding to notifier: ${err}')
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
eprintln('connected')
|
||||||
} else {
|
} else {
|
||||||
eprintln('unable to accept: ${err}')
|
eprintln('unable to accept: ${err}')
|
||||||
}
|
}
|
||||||
@ -57,11 +57,11 @@ fn main() {
|
|||||||
else {
|
else {
|
||||||
// remote connection
|
// remote connection
|
||||||
if event.kind.has(.peer_hangup) {
|
if event.kind.has(.peer_hangup) {
|
||||||
if _ := notifier.remove(event.fd) {
|
notifier.remove(event.fd) or {
|
||||||
eprintln('remote disconnected')
|
|
||||||
} else {
|
|
||||||
eprintln('error removing from notifier: ${err}')
|
eprintln('error removing from notifier: ${err}')
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
eprintln('remote disconnected')
|
||||||
} else {
|
} else {
|
||||||
s, _ := os.fd_read(event.fd, 10)
|
s, _ := os.fd_read(event.fd, 10)
|
||||||
os.fd_write(event.fd, s)
|
os.fd_write(event.fd, s)
|
||||||
|
@ -71,6 +71,11 @@ fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if mut branch.cond is ast.IfGuardExpr {
|
if mut branch.cond is ast.IfGuardExpr {
|
||||||
|
if branch.cond.expr_type.clear_flag(.option).clear_flag(.result) == ast.void_type
|
||||||
|
&& !(branch.cond.vars.len == 1 && branch.cond.vars[0].name == '_') {
|
||||||
|
c.error('if guard expects non-propagate option or result', branch.pos)
|
||||||
|
continue
|
||||||
|
}
|
||||||
sym := c.table.sym(branch.cond.expr_type)
|
sym := c.table.sym(branch.cond.expr_type)
|
||||||
if sym.kind == .multi_return {
|
if sym.kind == .multi_return {
|
||||||
mr_info := sym.info as ast.MultiReturn
|
mr_info := sym.info as ast.MultiReturn
|
||||||
|
7
vlib/v/checker/tests/if_guard_expr_err.out
Normal file
7
vlib/v/checker/tests/if_guard_expr_err.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
vlib/v/checker/tests/if_guard_expr_err.vv:6:7: error: if guard expects non-propagate option or result
|
||||||
|
4 |
|
||||||
|
5 | fn main() {
|
||||||
|
6 | a := if r := foo() {
|
||||||
|
| ~~~~~~~~~~~~~
|
||||||
|
7 | println(r)
|
||||||
|
8 | true
|
14
vlib/v/checker/tests/if_guard_expr_err.vv
Normal file
14
vlib/v/checker/tests/if_guard_expr_err.vv
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
fn foo() ! {
|
||||||
|
return error("error")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
a := if r := foo() {
|
||||||
|
println(r)
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
println(a)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user