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