diff --git a/lib/std/collections/list.c3 b/lib/std/collections/list.c3 index f4189b219..6b5869f3e 100644 --- a/lib/std/collections/list.c3 +++ b/lib/std/collections/list.c3 @@ -532,7 +532,8 @@ fn bool List.remove_first_item(&self, Type value) @if(ELEMENT_IS_EQUATABLE) fn usz List.remove_item(&self, Type value) @if(ELEMENT_IS_EQUATABLE) { usz old_size = self.size; - defer { + defer + { if (old_size != self.size) self._update_size_change(old_size, self.size); } return list_common::list_remove_item(self, value); diff --git a/releasenotes.md b/releasenotes.md index 2680a7fbb..1e7b1d6d5 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -16,6 +16,7 @@ - Fix fmod `a %= 0f`. - Regression vector ABI: initializing a struct containing a NPOT vector with a constant value would crash LLVM. #2559 - Error message with hashmap shows "mangled" name instead of original #2562. +- Passing a compile time type implicitly converted to a typeid would crash instead of producing an error. #2568 ### Stdlib changes diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 079483c9f..13500ccc6 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -4183,6 +4183,7 @@ INLINE void expr_rewrite_const_slice(Expr *expr, Type *type, ConstInitializer *i INLINE void expr_rewrite_const_typeid(Expr *expr, Type *type) { + ASSERT(type->type_kind != TYPE_UNTYPED_LIST); expr->expr_kind = EXPR_CONST; expr->const_expr.const_kind = CONST_TYPEID; expr->const_expr.typeid = type->canonical; diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index c5becd00d..7851aa552 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -6103,11 +6103,7 @@ static inline bool sema_expr_analyse_access(SemaContext *context, Expr *expr, bo 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; + expr_rewrite_const_typeid(expr, parent->type_expr->type->canonical); return true; } UNREACHABLE @@ -11737,8 +11733,15 @@ static inline bool sema_cast_rvalue(SemaContext *context, Expr *expr, bool mutat if (mutate) sema_expr_flatten_const_ident(expr->access_resolved_expr.parent); return true; case EXPR_TYPEINFO: - expr_rewrite_const_typeid(expr, expr->type_expr->type); - return true; + switch (expr->type_expr->type->type_kind) + { + case CT_TYPES: + RETURN_SEMA_ERROR(expr, "You cannot take the typeid of a compile time type."); + default: + expr_rewrite_const_typeid(expr, expr->type_expr->type); + return true; + } + UNREACHABLE case EXPR_CT_IDENT: if (mutate && !sema_cast_ct_ident_rvalue(context, expr)) return false; break; diff --git a/test/test_suite/compile_time/typeid_implicit_ct.c3 b/test/test_suite/compile_time/typeid_implicit_ct.c3 new file mode 100644 index 000000000..42ac6dbad --- /dev/null +++ b/test/test_suite/compile_time/typeid_implicit_ct.c3 @@ -0,0 +1,11 @@ +module test; +import std; +macro test(x) +{ + var $Type = $typeof(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