diff --git a/releasenotes.md b/releasenotes.md index 38b59acc1..e4b1e9d62 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -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. diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index bdfb18ca5..e64eb63f3 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -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; diff --git a/test/test_suite/define/alias_typename.c3 b/test/test_suite/define/alias_typename.c3 new file mode 100644 index 000000000..dd659fbbe --- /dev/null +++ b/test/test_suite/define/alias_typename.c3 @@ -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 \ No newline at end of file diff --git a/test/test_suite/define/common.c3 b/test/test_suite/define/common.c3 index aec56d615..d510b562f 100644 --- a/test/test_suite/define/common.c3 +++ b/test/test_suite/define/common.c3 @@ -9,7 +9,7 @@ def A_CONST_INT = A_CONST(); def standard_foo() = 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.