Improve error message when providing alias with a typeid expression where a type was expected. #2944

This commit is contained in:
Christoffer Lerno
2026-02-17 13:02:34 +01:00
parent 8cb23cff29
commit 3ac701be0e
3 changed files with 16 additions and 2 deletions

View File

@@ -16,6 +16,7 @@
- Add `@constinit` to allow old typedef behaviour. - 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. - 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. - 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 ### Stdlib changes
- Summarize sort macros as generic function wrappers to reduce the amount of generated code. #2831 - Summarize sort macros as generic function wrappers to reduce the amount of generated code. #2831

View File

@@ -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."); 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; 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: 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; return poisoned_decl;
} }
ASSERT(!tok_is(c, TOKEN_LBRACE)); ASSERT(!tok_is(c, TOKEN_LBRACE));

View File

@@ -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()
{
}