mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
75ebac006d
commit
04654ed518
@ -11,12 +11,12 @@ fn test_that_net_and_net_unix_can_be_imported_together_without_conflicts() ? {
|
||||
mut l := unix.listen_stream(test_port) or { panic(err) }
|
||||
go echo_server(mut l)
|
||||
defer {
|
||||
l.close() ?
|
||||
l.close() or {}
|
||||
}
|
||||
//
|
||||
mut c := unix.connect_stream(test_port) ?
|
||||
defer {
|
||||
c.close() ?
|
||||
c.close() or {}
|
||||
}
|
||||
//
|
||||
data := 'Hello from vlib/net!'
|
||||
|
@ -2694,6 +2694,10 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr {
|
||||
// `foo()?`
|
||||
if p.tok.kind == .question {
|
||||
p.next()
|
||||
if p.inside_defer {
|
||||
p.error_with_pos('error propagation not allowed inside `defer` blocks',
|
||||
p.prev_tok.pos())
|
||||
}
|
||||
or_kind = .propagate
|
||||
}
|
||||
//
|
||||
|
7
vlib/v/parser/tests/defer_propagate2.out
Normal file
7
vlib/v/parser/tests/defer_propagate2.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/parser/tests/defer_propagate2.vv:16:13: error: error propagation not allowed inside `defer` blocks
|
||||
14 | dump(s.x)
|
||||
15 | defer {
|
||||
16 | s.close() ?
|
||||
| ^
|
||||
17 | }
|
||||
18 | return s.x
|
23
vlib/v/parser/tests/defer_propagate2.vv
Normal file
23
vlib/v/parser/tests/defer_propagate2.vv
Normal file
@ -0,0 +1,23 @@
|
||||
struct Abc {
|
||||
mut:
|
||||
x int = 123
|
||||
}
|
||||
|
||||
fn (mut s Abc) close() ? {
|
||||
println('> CLOSE 1 s.x: $s.x')
|
||||
s.x = -1
|
||||
println('> CLOSE 2 s.x: $s.x')
|
||||
}
|
||||
|
||||
fn opt2() ?int {
|
||||
mut s := Abc{}
|
||||
dump(s.x)
|
||||
defer {
|
||||
s.close() ?
|
||||
}
|
||||
return s.x
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println(opt2() ?)
|
||||
}
|
Loading…
Reference in New Issue
Block a user