diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 080c68ff7..9734f3899 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -6370,10 +6370,11 @@ static inline bool sema_expr_analyse_access(SemaContext *context, Expr *expr, bo if (parent->expr_kind == EXPR_TYPEINFO) { Type *type = parent->type_expr->type->canonical; - switch (type->type_kind) + switch (type_no_optional(type)->type_kind) { case CT_TYPES: RETURN_SEMA_ERROR(parent, "You cannot take the typeid of a compile time type."); + default: expr_rewrite_const_typeid(expr, parent->type_expr->type->canonical); return true; @@ -12068,7 +12069,7 @@ static inline bool sema_cast_rvalue(SemaContext *context, Expr *expr, bool mutat } return true; case EXPR_TYPEINFO: - switch (expr->type_expr->type->type_kind) + switch (type_no_optional(expr->type_expr->type)->type_kind) { case CT_TYPES: RETURN_SEMA_ERROR(expr, "You cannot take the typeid of a compile time type."); diff --git a/test/test_suite/compile_time/typeof_untyped.c3 b/test/test_suite/compile_time/typeof_untyped.c3 new file mode 100644 index 000000000..6b529778c --- /dev/null +++ b/test/test_suite/compile_time/typeof_untyped.c3 @@ -0,0 +1,8 @@ +macro test(x) +{ +} +fn int main() +{ + test($typeof({})?); // #error: You cannot take the typeid of a compile time type + return 0; +} \ No newline at end of file