From aeaf607259be747709e475cf6972aaaeb6f2f1dd Mon Sep 17 00:00:00 2001 From: Leo Developer Date: Wed, 27 Nov 2024 14:29:13 +0100 Subject: [PATCH] log: tag log.fatal with @[noreturn] (#22986) --- vlib/log/default.v | 4 ++++ vlib/log/log_test.v | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/vlib/log/default.v b/vlib/log/default.v index d672afc6aa..5222af43cb 100644 --- a/vlib/log/default.v +++ b/vlib/log/default.v @@ -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 diff --git a/vlib/log/log_test.v b/vlib/log/log_test.v index aedb37e6e9..7195191009 100644 --- a/vlib/log/log_test.v +++ b/vlib/log/log_test.v @@ -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') } +}