mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: clean error when nesting unsafe
(#6656)
This commit is contained in:
parent
d881185d79
commit
21db4b338b
@ -2012,7 +2012,9 @@ fn (mut p Parser) unsafe_stmt() ast.Stmt {
|
||||
p.error_with_pos('please use `unsafe {`', p.tok.position())
|
||||
}
|
||||
p.next()
|
||||
assert !p.inside_unsafe
|
||||
if p.inside_unsafe {
|
||||
p.error_with_pos('already inside `unsafe` block', pos)
|
||||
}
|
||||
if p.tok.kind == .rcbr {
|
||||
// `unsafe {}`
|
||||
p.next()
|
||||
|
@ -92,9 +92,11 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
|
||||
}
|
||||
.key_unsafe {
|
||||
// unsafe {
|
||||
p.next()
|
||||
pos := p.tok.position()
|
||||
assert !p.inside_unsafe
|
||||
p.next()
|
||||
if p.inside_unsafe {
|
||||
p.error_with_pos('already inside `unsafe` block', pos)
|
||||
}
|
||||
p.inside_unsafe = true
|
||||
p.check(.lcbr)
|
||||
node = ast.UnsafeExpr{
|
||||
|
7
vlib/v/parser/tests/nested_unsafe_expr.out
Normal file
7
vlib/v/parser/tests/nested_unsafe_expr.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/parser/tests/nested_unsafe_expr.vv:4:8: error: already inside `unsafe` block
|
||||
2 | a := 0
|
||||
3 | unsafe {
|
||||
4 | a += unsafe{2}
|
||||
| ~~~~~~
|
||||
5 | }
|
||||
6 | println(a)
|
7
vlib/v/parser/tests/nested_unsafe_expr.vv
Normal file
7
vlib/v/parser/tests/nested_unsafe_expr.vv
Normal file
@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
a := 0
|
||||
unsafe {
|
||||
a += unsafe{2}
|
||||
}
|
||||
println(a)
|
||||
}
|
7
vlib/v/parser/tests/nested_unsafe_stmt.out
Normal file
7
vlib/v/parser/tests/nested_unsafe_stmt.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/parser/tests/nested_unsafe_stmt.vv:4:3: error: already inside `unsafe` block
|
||||
2 | a := 0
|
||||
3 | unsafe {
|
||||
4 | unsafe {
|
||||
| ~~~~~~
|
||||
5 | a++
|
||||
6 | }
|
9
vlib/v/parser/tests/nested_unsafe_stmt.vv
Normal file
9
vlib/v/parser/tests/nested_unsafe_stmt.vv
Normal file
@ -0,0 +1,9 @@
|
||||
fn main() {
|
||||
a := 0
|
||||
unsafe {
|
||||
unsafe {
|
||||
a++
|
||||
}
|
||||
}
|
||||
println(a)
|
||||
}
|
Loading…
Reference in New Issue
Block a user