checker: check return_duplicate_with_none (closes #5363)
parent
b93177c1a8
commit
2785a5bf65
|
@ -798,7 +798,8 @@ pub mut:
|
||||||
|
|
||||||
pub struct None {
|
pub struct None {
|
||||||
pub:
|
pub:
|
||||||
foo int // todo
|
pos token.Position
|
||||||
|
foo int // todo
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
|
@ -874,6 +875,9 @@ pub fn (expr Expr) position() token.Position {
|
||||||
MatchExpr {
|
MatchExpr {
|
||||||
return it.pos
|
return it.pos
|
||||||
}
|
}
|
||||||
|
None {
|
||||||
|
return it.pos
|
||||||
|
}
|
||||||
PostfixExpr {
|
PostfixExpr {
|
||||||
return it.pos
|
return it.pos
|
||||||
}
|
}
|
||||||
|
|
|
@ -1793,7 +1793,7 @@ fn (mut c Checker) stmts(stmts []ast.Stmt) {
|
||||||
c.stmt(stmt)
|
c.stmt(stmt)
|
||||||
}
|
}
|
||||||
if unreachable.line_nr >= 0 {
|
if unreachable.line_nr >= 0 {
|
||||||
c.warn('unreachable code', unreachable)
|
c.error('unreachable code', unreachable)
|
||||||
}
|
}
|
||||||
c.scope_returns = false
|
c.scope_returns = false
|
||||||
c.expected_type = table.void_type
|
c.expected_type = table.void_type
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
vlib/v/checker/tests/return_duplicate_with_none_err_a.v:3:2: error: unreachable code
|
||||||
|
1 | fn f() ?bool {
|
||||||
|
2 | return true
|
||||||
|
3 | return none
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
4 | }
|
||||||
|
5 | fn main() {
|
|
@ -0,0 +1,9 @@
|
||||||
|
fn f() ?bool {
|
||||||
|
return true
|
||||||
|
return none
|
||||||
|
}
|
||||||
|
fn main() {
|
||||||
|
f() or {
|
||||||
|
println('fail')
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
vlib/v/checker/tests/return_duplicate_with_none_err_b.v:3:2: error: unreachable code
|
||||||
|
1 | fn f() ?bool {
|
||||||
|
2 | return none
|
||||||
|
3 | return true
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
4 | }
|
||||||
|
5 | fn main() {
|
|
@ -0,0 +1,9 @@
|
||||||
|
fn f() ?bool {
|
||||||
|
return none
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
fn main() {
|
||||||
|
f() or {
|
||||||
|
println('fail')
|
||||||
|
}
|
||||||
|
}
|
|
@ -73,8 +73,11 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.key_none {
|
.key_none {
|
||||||
|
pos := p.tok.position()
|
||||||
p.next()
|
p.next()
|
||||||
node = ast.None{}
|
node = ast.None{
|
||||||
|
pos: pos
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.key_sizeof {
|
.key_sizeof {
|
||||||
p.next() // sizeof
|
p.next() // sizeof
|
||||||
|
|
Loading…
Reference in New Issue