Improve error message when using void aliases as variable storage type.

This commit is contained in:
Christoffer Lerno
2024-11-01 14:56:29 +01:00
parent fd5b8d1374
commit b06a611e69
2 changed files with 5 additions and 3 deletions

View File

@@ -21,6 +21,7 @@
- Null-check function pointer invocation #1573. - Null-check function pointer invocation #1573.
- `string::new_struct_to_str` and `io::struct_to_format` to dump struct data. - `string::new_struct_to_str` and `io::struct_to_format` to dump struct data.
- `io::print` will now print structs. - `io::print` will now print structs.
- Improve error message when using `void` aliases as variable storage type.
### Fixes ### Fixes
- `Unsupported int[*] $x = { 1, 2, 3, 4 }` #1489. - `Unsupported int[*] $x = { 1, 2, 3, 4 }` #1489.

View File

@@ -3666,11 +3666,12 @@ static bool sema_analyse_variable_type(SemaContext *context, Type *type, SourceS
case STORAGE_WILDCARD: case STORAGE_WILDCARD:
if (type_is_optional(type)) 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) { ... }'," "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: case STORAGE_COMPILE_TIME:
RETURN_SEMA_ERROR_AT(span, "The variable cannot have an compile time %s type.", RETURN_SEMA_ERROR_AT(span, "The variable cannot have an compile time %s type.",
type_quoted_error_string(type)); type_quoted_error_string(type));