Improved error message when declaring a variable void!.

This commit is contained in:
Christoffer Lerno
2024-10-11 00:15:49 +02:00
parent bf30e52993
commit cf07570871
3 changed files with 11 additions and 13 deletions

View File

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

View File

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