Fix typeid on compile time types.

This commit is contained in:
Christoffer Lerno
2025-07-01 00:27:17 +02:00
parent ba11511c69
commit 4502a9286c
2 changed files with 26 additions and 6 deletions

View File

@@ -5310,6 +5310,13 @@ EVAL:
static bool sema_type_property_is_valid_for_type(CanonicalType *original_type, TypeProperty property)
{
switch (original_type->type_kind)
{
case CT_TYPES:
return false;
default:
break;
}
CanonicalType *type = type_flatten(original_type);
switch (property)
{
@@ -5755,12 +5762,20 @@ static inline bool sema_expr_analyse_access(SemaContext *context, Expr *expr, bo
}
if (parent->expr_kind == EXPR_TYPEINFO)
{
expr->type = type_typeid;
expr->expr_kind = EXPR_CONST;
expr->const_expr.const_kind = CONST_TYPEID;
expr->const_expr.typeid = parent->type_expr->type->canonical;
expr->resolve_status = RESOLVE_DONE;
return true;
Type *type = parent->type_expr->type->canonical;
switch (type->type_kind)
{
case CT_TYPES:
RETURN_SEMA_ERROR(parent, "You cannot take the typeid of a compile time type.");
default:
expr->type = type_typeid;
expr->expr_kind = EXPR_CONST;
expr->const_expr.const_kind = CONST_TYPEID;
expr->const_expr.typeid = parent->type_expr->type->canonical;
expr->resolve_status = RESOLVE_DONE;
return true;
}
UNREACHABLE
}
if (expr_is_const_member(parent))
{

View File

@@ -0,0 +1,5 @@
fn void main()
{
typeid t = $typeof({1, "hts"}).typeid; // #error: cannot take the typeid
$typeof({1, "hts"}).nameof; // #error: does not have a property or method
}