Improved error messages on Foo a = foo { 1 }; #1496

This commit is contained in:
Christoffer Lerno
2024-09-28 23:53:31 +02:00
parent 3b009e0b50
commit 2e94ea1a0d
2 changed files with 7 additions and 1 deletions

View File

@@ -63,6 +63,7 @@
- Safer seed of rand() for WASM without libc.
- Bad error message aliasing an ident with a path. #1481.
- Error when slicing a struct with an inline array #1488.
- Improved error messages on `Foo a = foo { 1 };` #1496
### Stdlib changes
- Additional init functions for hashmap.

View File

@@ -15,9 +15,14 @@ static Ast *parse_decl_stmt_after_type(ParseContext *c, TypeInfo *type)
ast->span = type->span;
ast->ast_kind = AST_DECLARE_STMT;
ASSIGN_DECL_OR_RET(ast->declare_stmt, parse_local_decl_after_type(c, type), poisoned_ast);
Decl *decl = ast->declare_stmt;
if (tok_is(c, TOKEN_LBRACE) && decl->var.init_expr && decl->var.init_expr->expr_kind == EXPR_IDENTIFIER)
{
print_error_at(decl->var.init_expr->span, "An identifier would not usually be followed by a '{'. Did you intend write the name of a type here?");
return poisoned_ast;
}
if (tok_is(c, TOKEN_EOS)) return ast;
Decl *decl = ast->declare_stmt;
if (decl->attributes || decl->var.init_expr)
{
if (tok_is(c, TOKEN_COMMA) && peek(c) == TOKEN_IDENT)