Improve error messages on expressions like var $type = int; #1553.

This commit is contained in:
Christoffer Lerno
2024-10-15 11:50:15 +02:00
parent cf03bc0a0a
commit 4445b6c054
2 changed files with 7 additions and 0 deletions

View File

@@ -3746,6 +3746,11 @@ bool sema_analyse_var_decl_ct(SemaContext *context, Decl *decl)
// If we don't have a type, resolve the expression.
if ((init = decl->var.init_expr))
{
if (init->expr_kind == EXPR_TYPEINFO)
{
SEMA_ERROR(init, "You can't assign a type to a regular compile time variable like '%s', but it would be allowed if the variable was a compile time type variable. Such a variable needs to have a type-like name, e.g. '$MyType'.", decl->name);
goto FAIL;
}
if (!sema_analyse_expr(context, init)) goto FAIL;
// Check it is constant.
if (!expr_is_runtime_const(init))