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

log: mark log.fatal as [noreturn] (#16129)

This commit is contained in:
bogen85 2022-10-21 02:33:49 -05:00 committed by GitHub
parent 51f4d99399
commit c684dd8c9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View File

@ -19,6 +19,4 @@ fn main() {
l.set_level(log.level_from_tag('') or { log.Level.disabled }) // set level from string, sample
l.error('no output anymore')
l.fatal('fatal') // panic, next statements won't be executed
l.set_level(.info)
l.warn('warn')
}

11
examples/logfatal.v Normal file
View File

@ -0,0 +1,11 @@
import log
[noreturn]
fn should_not_return(mut logger log.Log) {
logger.fatal('${@FILE_LINE}: yikes!')
}
fn main() {
mut my_log := log.Log{}
should_not_return(mut my_log)
}

View File

@ -179,6 +179,7 @@ pub fn (mut l Log) send_output(s &string, level Level) {
// fatal logs line `s` via `send_output` if `Log.level` is greater than or equal to the `Level.fatal` category.
// Note that this method performs a panic at the end, even if log level is not enabled.
[noreturn]
pub fn (mut l Log) fatal(s string) {
if int(l.level) >= int(Level.fatal) {
l.send_output(s, .fatal)