diff --git a/releasenotes.md b/releasenotes.md index 0f7bf88d6..6781a2be8 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -16,7 +16,8 @@ - Add `@constinit` to allow old typedef behaviour. - Include actual element count in the error message when the array initializer size does not match the expected size. - Add `--print-large-functions` for checking which functions likely dominate the compile time. - +- Improve error message when providing `alias` with a typeid expression where a type was expected. #2944 + ### Stdlib changes - Summarize sort macros as generic function wrappers to reduce the amount of generated code. #2831 - Remove dependency on temp allocator in String.join. diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index 22cd7074b..2d6bfb5a5 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -2421,8 +2421,12 @@ static inline Decl *parse_alias_type(ParseContext *c, AstId contracts) 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; + case EXPR_TERNARY: + case EXPR_CALL: + PRINT_ERROR_AT(expr, "Expected a type to alias here, if you are providing a constant typeid-expression, e.g. 'FOO > 32 ??? long : int', then you need to wrap the expression in '$typefrom'"); + return poisoned_decl; default: - PRINT_ERROR_HERE("Expected a type to alias here."); + PRINT_ERROR_AT(expr, "Expected the name of the type to alias here."); return poisoned_decl; } ASSERT(!tok_is(c, TOKEN_LBRACE)); diff --git a/test/test_suite/define/alias_should_typefrom.c3 b/test/test_suite/define/alias_should_typefrom.c3 new file mode 100644 index 000000000..9390ca494 --- /dev/null +++ b/test/test_suite/define/alias_should_typefrom.c3 @@ -0,0 +1,9 @@ +import std; + +const C = 2; +alias BaseType = C < 32 ??? int : long; // #error: Expected a type to alias here, if you are providing a constant typeid-expression + +fn void main() +{ + +} \ No newline at end of file