From b06a611e69592c19cb167f392b0b221b22ffc277 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 1 Nov 2024 14:56:29 +0100 Subject: [PATCH] Improve error message when using `void` aliases as variable storage type. --- releasenotes.md | 1 + src/compiler/sema_decls.c | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/releasenotes.md b/releasenotes.md index cc071f33f..33cb0c070 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -21,6 +21,7 @@ - Null-check function pointer invocation #1573. - `string::new_struct_to_str` and `io::struct_to_format` to dump struct data. - `io::print` will now print structs. +- Improve error message when using `void` aliases as variable storage type. ### Fixes - `Unsupported int[*] $x = { 1, 2, 3, 4 }` #1489. diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index 62ba62dcc..c60ec7c6b 100755 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -3666,11 +3666,12 @@ static bool sema_analyse_variable_type(SemaContext *context, Type *type, SourceS case STORAGE_WILDCARD: if (type_is_optional(type)) { - RETURN_SEMA_ERROR_AT(span, "The use of 'void!' as a variable type is not permitted, " + RETURN_SEMA_ERROR_AT(span, "The use of %s as a variable type is not permitted, " "catch the error using 'if (catch err = foo) { ... }'," - " or use '@catch(foo)' to convert it to an 'anyfault'."); + " or use '@catch(foo)' to convert it to an 'anyfault'.", + type_quoted_error_string(type)); } - RETURN_SEMA_ERROR_AT(span, "The use of 'void' as a variable type is not permitted."); + RETURN_SEMA_ERROR_AT(span, "The use of %s as a variable type is not permitted.", type_quoted_error_string(type)); case STORAGE_COMPILE_TIME: RETURN_SEMA_ERROR_AT(span, "The variable cannot have an compile time %s type.", type_quoted_error_string(type));