mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Bad error message aliasing an ident with a path. #1481.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
2
test/test_suite/define/alias_typename.c3
Normal file
2
test/test_suite/define/alias_typename.c3
Normal 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
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user