checker: check return_duplicate_with_none (closes #5363)
							parent
							
								
									b93177c1a8
								
							
						
					
					
						commit
						2785a5bf65
					
				|  | @ -798,6 +798,7 @@ pub mut: | |||
| 
 | ||||
| pub struct None { | ||||
| pub: | ||||
| 	pos  token.Position | ||||
| 	foo  int // todo
 | ||||
| } | ||||
| 
 | ||||
|  | @ -874,6 +875,9 @@ pub fn (expr Expr) position() token.Position { | |||
| 		MatchExpr { | ||||
| 			return it.pos | ||||
| 		} | ||||
| 		None { | ||||
| 			return it.pos | ||||
| 		} | ||||
| 		PostfixExpr { | ||||
| 			return it.pos | ||||
| 		} | ||||
|  |  | |||
|  | @ -1793,7 +1793,7 @@ fn (mut c Checker) stmts(stmts []ast.Stmt) { | |||
| 		c.stmt(stmt) | ||||
| 	} | ||||
| 	if unreachable.line_nr >= 0 { | ||||
| 		c.warn('unreachable code', unreachable) | ||||
| 		c.error('unreachable code', unreachable) | ||||
| 	} | ||||
| 	c.scope_returns = false | ||||
| 	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 { | ||||
| 			pos := p.tok.position() | ||||
| 			p.next() | ||||
| 			node = ast.None{} | ||||
| 			node = ast.None{ | ||||
| 				pos: pos | ||||
| 			} | ||||
| 		} | ||||
| 		.key_sizeof { | ||||
| 			p.next() // sizeof
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue