parser,checker: allow a goto label right after return
							parent
							
								
									8cd01e0eac
								
							
						
					
					
						commit
						1b6cccaf6d
					
				| 
						 | 
				
			
			@ -5162,6 +5162,12 @@ fn (mut c Checker) stmts(stmts []ast.Stmt) {
 | 
			
		|||
			}
 | 
			
		||||
		}
 | 
			
		||||
		c.stmt(stmt)
 | 
			
		||||
		if stmt is ast.GotoLabel {
 | 
			
		||||
			unreachable = token.Position{
 | 
			
		||||
				line_nr: -1
 | 
			
		||||
			}
 | 
			
		||||
			c.scope_returns = false
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if unreachable.line_nr >= 0 {
 | 
			
		||||
		c.error('unreachable code', unreachable)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2974,7 +2974,7 @@ fn (mut p Parser) return_stmt() ast.Return {
 | 
			
		|||
	p.next()
 | 
			
		||||
	// no return
 | 
			
		||||
	mut comments := p.eat_comments()
 | 
			
		||||
	if p.tok.kind == .rcbr {
 | 
			
		||||
	if p.tok.kind == .rcbr || ( p.tok.kind == .name && p.peek_tok.kind == .colon ) {
 | 
			
		||||
		return ast.Return{
 | 
			
		||||
			comments: comments
 | 
			
		||||
			pos: first_pos
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,3 +11,28 @@ fn test_goto() {
 | 
			
		|||
	}
 | 
			
		||||
	assert i == 3
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn test_goto_after_return() {
 | 
			
		||||
	a, b, c, d := 4, 5, 6, 7
 | 
			
		||||
	for {
 | 
			
		||||
		for {
 | 
			
		||||
			for {
 | 
			
		||||
				if a == 4 {
 | 
			
		||||
					if b == 5 {
 | 
			
		||||
						if c == 6 {
 | 
			
		||||
							if d == 7 {
 | 
			
		||||
								unsafe {
 | 
			
		||||
									goto finally_ok
 | 
			
		||||
								}
 | 
			
		||||
							}
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	assert false
 | 
			
		||||
	return
 | 
			
		||||
	finally_ok:
 | 
			
		||||
	assert true
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue