Skip to content

Commit

Permalink
log: tag log.fatal with @[noreturn] (#22986)
Browse files Browse the repository at this point in the history
  • Loading branch information
Le0Developer authored Nov 27, 2024
1 parent 844d89f commit aeaf607
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vlib/log/default.v
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ pub fn set_level(level Level) {
}

// fatal logs a `fatal` message, using the default Logger instance
@[noreturn]
pub fn fatal(s string) {
default_logger.fatal(s)
// the compiler currently has no way to mark functions in an interface
// as @[noreturn], so we need to make sure this is never returning ourselves
exit(1)
}

// error logs an `error` message, using the default Logger instance
Expand Down
8 changes: 8 additions & 0 deletions vlib/log/log_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,11 @@ fn test_log_time_format() {
assert true
println(@FN + ' end')
}

fn make_error() ?string {
return 'ok'
}

fn test_log_default_fatal_has_noreturn() {
_ := make_error() or { fatal('error') }
}

0 comments on commit aeaf607

Please sign in to comment.