log: tag log.fatal with @[noreturn] (#22986)

This commit is contained in:
Leo Developer 2024-11-27 14:29:13 +01:00 committed by GitHub
parent 844d89fd09
commit aeaf607259
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View File

@ -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

View File

@ -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') }
}