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:
parent
6eaa06c0c7
commit
1db67f7505
|
@ -303,6 +303,10 @@ fn has_top_return(stmts []ast.Stmt) bool {
|
||||||
|| (stmt.expr.is_method == false && stmt.expr.name == 'panic') {
|
|| (stmt.expr.is_method == false && stmt.expr.name == 'panic') {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
} else if stmt.expr is ast.ComptimeCall {
|
||||||
|
if stmt.expr.method_name == 'compile_error' {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {}
|
else {}
|
||||||
|
|
|
@ -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 | }
|
12
vlib/v/checker/tests/comptime_else_compile_error_no_return.vv
Executable file
12
vlib/v/checker/tests/comptime_else_compile_error_no_return.vv
Executable 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{})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user