1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: allow no return in compile_error else block (#18758)

This commit is contained in:
phoebe 2023-07-04 05:44:24 +02:00 committed by GitHub
parent 6eaa06c0c7
commit 1db67f7505
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 0 deletions

View File

@ -303,6 +303,10 @@ fn has_top_return(stmts []ast.Stmt) bool {
|| (stmt.expr.is_method == false && stmt.expr.name == 'panic') {
return true
}
} else if stmt.expr is ast.ComptimeCall {
if stmt.expr.method_name == 'compile_error' {
return true
}
}
}
else {}

View File

@ -0,0 +1,7 @@
vlib/v/checker/tests/comptime_else_compile_error_no_return.vv:5:3: error: not an int
3 | return val
4 | } $else {
5 | $compile_error('not an int')
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 | }
7 | }

View File

@ -0,0 +1,12 @@
fn onlyint[T](val T) T {
$if val is $int {
return val
} $else {
$compile_error('not an int')
}
}
fn main() {
onlyint(7)
onlyint([]int{})
}