Disallow typeof of member type.

This commit is contained in:
Christoffer Lerno
2022-10-07 22:28:30 +02:00
parent bb20a38cdb
commit c84f82559c
2 changed files with 22 additions and 0 deletions

View File

@@ -2506,6 +2506,18 @@ INLINE bool type_is_float(Type *type)
return kind >= TYPE_FLOAT_FIRST && kind <= TYPE_FLOAT_LAST;
}
INLINE bool type_is_invalid_for_typeof(Type *type)
{
switch (type->type_kind)
{
case TYPE_MEMBER:
case TYPE_UNTYPED_LIST:
return true;
default:
return false;
}
}
INLINE TypeInfo *type_info_new(TypeInfoKind kind, SourceSpan span)
{
TypeInfo *type_info = type_info_calloc();

View File

@@ -308,6 +308,11 @@ bool sema_resolve_type_shallow(SemaContext *context, TypeInfo *type_info, bool a
SEMA_ERROR(expr, "Only type names may be resolved with $evaltype.");
return type_info_poison(type_info);
}
if (type_is_invalid_for_typeof(expr->type))
{
SEMA_ERROR(expr, "Compile-time expressions may not be used with $evaltype.");
return type_info_poison(type_info);
}
TypeInfo *inner_type = inner->type_expr;
if (!sema_resolve_type_info(context, inner_type)) return false;
type_info->type = inner_type->type;
@@ -321,6 +326,11 @@ bool sema_resolve_type_shallow(SemaContext *context, TypeInfo *type_info, bool a
{
return type_info_poison(type_info);
}
if (type_is_invalid_for_typeof(expr->type))
{
SEMA_ERROR(expr, "Compile-time expressions are not allowed here.");
return false;
}
type_info->type = expr->type;
type_info->resolve_status = RESOLVE_DONE;
assert(!type_info->failable);