diff --git a/releasenotes.md b/releasenotes.md index 3fc734298..5eb92de97 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -11,7 +11,6 @@ - Deprecate `@adhoc`, allow non-nested ad hoc generic types. - Constant bytes <=> char[] conversion should work #1514. - Infer now works across ternary. -- Improved error message on invalid subscript index type #1535. ### Fixes - `Unsupported int[*] $x = { 1, 2, 3, 4 }` #1489. @@ -26,6 +25,8 @@ - Bug when defers and $if were combined in a macro, which would cause miscompilation. - Fixes to the CSV reader. - Crash returning struct or vector from function using ternary expression #1537. +- Improved error message on invalid subscript index type #1535. +- Improved error message when declaring a variable `void!`. ### Stdlib changes - Remove unintended print of `char[]` as String diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index dbf5a95fd..e28d47d3c 100755 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -3659,21 +3659,17 @@ static bool sema_analyse_decl_type(SemaContext *context, Type *type, SourceSpan case STORAGE_WILDCARD: if (type_is_optional(type)) { - sema_error_at(context, span, "The use of 'void!' as a variable type is not permitted, use %s instead.", - type_quoted_error_string(type_anyfault)); - } else - { - sema_error_at(context, span, "The use of 'void' as a variable type is not permitted."); + RETURN_SEMA_ERROR_AT(span, "The use of 'void!' 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'."); } - return false; + RETURN_SEMA_ERROR_AT(span, "The use of 'void' as a variable type is not permitted."); case STORAGE_COMPILE_TIME: - sema_error_at(context, span, "The variable cannot have an compile time %s type.", - type_quoted_error_string(type)); - return false; + RETURN_SEMA_ERROR_AT(span, "The variable cannot have an compile time %s type.", + type_quoted_error_string(type)); case STORAGE_UNKNOWN: - sema_error_at(context, span, "%s has unknown size, and so it cannot be a variable type.", - type_quoted_error_string(type)); - return false; + RETURN_SEMA_ERROR_AT(span, "%s has unknown size, and so it cannot be a variable type.", + type_quoted_error_string(type)); } UNREACHABLE } diff --git a/src/compiler/sema_internal.h b/src/compiler/sema_internal.h index 8a55fb9b0..f41bae556 100644 --- a/src/compiler/sema_internal.h +++ b/src/compiler/sema_internal.h @@ -19,6 +19,7 @@ #define SEMA_ERROR(_node, ...) sema_error_at(context, (_node)->span, __VA_ARGS__) #define RETURN_SEMA_ERROR(_node, ...) do { sema_error_at(context, (_node)->span, __VA_ARGS__); return false; } while (0) +#define RETURN_SEMA_ERROR_AT(span__, ...) do { sema_error_at(context, span__, __VA_ARGS__); return false; } while (0) #ifdef NDEBUG #define ASSERT_SPANF(node__, check__, format__, ...) do { } while(0) #define ASSERT_SPAN(node__, check__) do { } while(0)