mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Disallow typeof of member type.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user