Skip to content

Commit aeaf607

Browse files
authored
log: tag log.fatal with @[noreturn] (#22986)
1 parent 844d89f commit aeaf607

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

vlib/log/default.v

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ pub fn set_level(level Level) {
3030
}
3131

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

3741
// error logs an `error` message, using the default Logger instance

vlib/log/log_test.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,11 @@ fn test_log_time_format() {
136136
assert true
137137
println(@FN + ' end')
138138
}
139+
140+
fn make_error() ?string {
141+
return 'ok'
142+
}
143+
144+
fn test_log_default_fatal_has_noreturn() {
145+
_ := make_error() or { fatal('error') }
146+
}

0 commit comments

Comments
 (0)