parser: check that functions return in all if/else branches
							parent
							
								
									28147c0930
								
							
						
					
					
						commit
						61983a6799
					
				|  | @ -927,6 +927,7 @@ fn (p mut Parser) fn_call_args(f mut Fn) *Fn { | |||
| 	} | ||||
| 	p.check(.rpar) | ||||
| 	// p.gen(')')
 | ||||
| 	return f // TODO is return f right?
 | ||||
| } | ||||
| 
 | ||||
| // "fn (int, string) int"
 | ||||
|  |  | |||
|  | @ -2928,6 +2928,8 @@ fn (p mut Parser) if_st(is_expr bool, elif_depth int) string { | |||
| 	else { | ||||
| 		typ = p.statements() | ||||
| 	} | ||||
| 	if_returns := p.returns | ||||
| 	p.returns = false | ||||
| 	// println('IF TYp=$typ')
 | ||||
| 	if p.tok == .key_else { | ||||
| 		p.fgenln('')  | ||||
|  | @ -2959,6 +2961,8 @@ fn (p mut Parser) if_st(is_expr bool, elif_depth int) string { | |||
| 		} | ||||
| 		return typ | ||||
| 	} | ||||
| 	else_returns := p.returns | ||||
| 	p.returns = if_returns && else_returns | ||||
| 	p.inside_if_expr = false | ||||
| 	if p.fileis('test_test') { | ||||
| 		println('if ret typ="$typ" line=$p.scanner.line_nr') | ||||
|  |  | |||
|  | @ -739,6 +739,8 @@ fn (t mut Table) fn_gen_types(fn_name string) []string { | |||
| 			return f.types | ||||
| 		}  | ||||
| 	}  | ||||
| 	panic('function $fn_name not found') // TODO panic or return []?
 | ||||
| 	return []string // TODO remove return
 | ||||
| }  | ||||
| 
 | ||||
| // `foo<Bar>()`
 | ||||
|  |  | |||
|  | @ -45,6 +45,7 @@ fn (p mut Parser) peek() Token { | |||
| 			return tok | ||||
| 		} | ||||
| 	} | ||||
| 	return .eof // TODO can never get here - v doesn't know that
 | ||||
| } | ||||
| 
 | ||||
| fn (p mut Parser) fmt_inc() { | ||||
|  |  | |||
|  | @ -36,10 +36,12 @@ fn (f mut Fetcher) fetch() { | |||
| 		resp := http.get('https://hacker-news.firebaseio.com/v0/item/${id}.json') or {
 | ||||
| 			println('failed to fetch data from /v0/item/${id}.json') | ||||
| 			exit(1) | ||||
| 			return // TODO remove return
 | ||||
| 		} | ||||
| 		story := json.decode(Story, resp.text) or { | ||||
| 			println('failed to decode a story') | ||||
| 			exit(1) | ||||
| 			return // TODO remove return
 | ||||
| 		} | ||||
| 		f.wg.done() | ||||
| 		println('#$cursor) $story.title | $story.url') | ||||
|  |  | |||
|  | @ -23,6 +23,7 @@ for /r . %%x in (*_test.v) do ( | |||
|   v -os msvc -o test.exe -debug %%x | ||||
|   if !ERRORLEVEL! NEQ 0 goto :fail | ||||
| ) | ||||
| 
 | ||||
| for /r . %%x in (*_test.v) do ( | ||||
|   v.msvc.exe -os msvc -o test.exe -debug %%x | ||||
|   if !ERRORLEVEL! NEQ 0 goto :fail | ||||
|  |  | |||
|  | @ -462,6 +462,7 @@ pub fn (s string) count(substr string) int { | |||
| 		i += substr.len | ||||
| 		n++ | ||||
| 	} | ||||
| 	return 0 // TODO can never get here - v doesn't know that
 | ||||
| } | ||||
| 
 | ||||
| pub fn (s string) contains(p string) bool { | ||||
|  |  | |||
|  | @ -489,8 +489,7 @@ pub fn (c Complex) acsch() Complex { | |||
| 		) | ||||
| 		.divide(c) | ||||
| 		.ln() | ||||
| 	} | ||||
| 	if(c.re > 0) { | ||||
| 	} else { | ||||
| 		return one.add( | ||||
| 			one.add( | ||||
| 				c.pow(2)  | ||||
|  |  | |||
|  | @ -19,6 +19,7 @@ pub fn fraction(n i64, d i64) Fraction{ | |||
| 	}  | ||||
| 	else { | ||||
| 		panic('Denominator cannot be zero') | ||||
| 		return Fraction{} // TODO remove return
 | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue