Skip to content

Commit

Permalink
Improve error message when using void aliases as variable storage t…
Browse files Browse the repository at this point in the history
…ype.
  • Loading branch information
lerno committed Nov 1, 2024
1 parent fd5b8d1 commit b06a611
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions src/compiler/sema_decls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit b06a611

Please sign in to comment.