Bad error message aliasing an ident with a path. #1481.

This commit is contained in:
Christoffer Lerno
2024-09-25 21:41:34 +02:00
parent da2f958614
commit bf9ae2f0d3
4 changed files with 26 additions and 3 deletions

View File

@@ -61,6 +61,7 @@
- Fix bug due to enum associated values not being checked for liveness.
- Regression when compile time accessing a union field not last assigned to.
- Safer seed of rand() for WASM without libc.
- Bad error message aliasing an ident with a path. #1481.
### Stdlib changes
- Additional init functions for hashmap.

View File

@@ -1901,8 +1901,28 @@ static inline Decl *parse_def_type(ParseContext *c)
}
// 2. Now parse the type which we know is here.
ASSIGN_TYPE_OR_RET(TypeInfo *type_info, parse_type(c), poisoned_decl);
ASSIGN_EXPR_OR_RET(Expr *expr, parse_expr(c), poisoned_decl);
TypeInfo *type_info;
switch (expr->expr_kind)
{
case EXPR_TYPEINFO:
type_info = expr->type_expr;
break;
case EXPR_IDENTIFIER:
if (expr->identifier_expr.is_const)
{
print_error_at(decl->span, "A constant may not have a type name alias, it must have an all caps name.");
}
else
{
print_error_at(decl->span, "An identifier may not be aliased with type name, it must start with a lower case letter.");
}
return poisoned_decl;
default:
PRINT_ERROR_HERE("Expected a type to alias here.");
return poisoned_decl;
}
assert(!tok_is(c, TOKEN_LGENPAR));
decl->typedef_decl.type_info = type_info;

View File

@@ -0,0 +1,2 @@
def ShouldNotBeUppercase = FOO; // #error: A constant may not have a type name
def ShouldNotBeUppercase2 = abc; // #error: An identifier may not be aliased

View File

@@ -9,7 +9,7 @@ def A_CONST_INT = A_CONST(<int>);
def standard_foo(<int>) = ofke; // #error: Expected '='
def fn foo = fef; // #error: A type, variable, constant or attribute name was expected here
def feokfe = fn void(int); // #error: This looks like you're declaring a function type alias
def Helo = helo; // #error: A type name was expected, but this looks a variable
def Helo = OFKE; // #error: A type name was expected here
def Helo = helo; // #error: An identifier may not be aliased
def Helo = OFKE; // #error: A constant may not have a type name alias
def int = int; // #error: 'int' is a reserved keyword, try another name
def main = foo; // #error: 'main' is reserved and cannot be used as an alias.