From 353a072b757a36abef6591d6832ecf51fd56c954 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sun, 14 May 2023 17:23:45 +0200 Subject: [PATCH] Fix for getting the correct generic type of consts. Fix of late initialization of structs using compound literals. --- src/compiler/llvm_codegen.c | 1 + src/compiler/sema_decls.c | 4 +++- src/compiler/sema_expr.c | 5 +++-- src/compiler/sema_initializers.c | 1 + src/version.h | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index 0ee98a554..3c2a8ba60 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -275,6 +275,7 @@ LLVMValueRef llvm_emit_const_initializer(GenContext *c, ConstInitializer *const_ LLVMTypeRef expected_type = llvm_get_type(c, const_init->init_struct[i]->type); LLVMValueRef element = llvm_emit_const_initializer(c, const_init->init_struct[i]); LLVMTypeRef element_type = LLVMTypeOf(element); + assert(LLVMIsConstant(element)); if (expected_type != element_type) { was_modified = true; diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index c499bef22..802525aae 100644 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -3068,11 +3068,13 @@ static bool sema_analyse_parameterized_define(SemaContext *c, Decl *decl) } } assert(symbol); + if (!sema_analyse_decl(c, symbol)) return false; unit_register_external_symbol(c->compilation_unit, symbol); switch (decl->define_decl.define_kind) { case DEFINE_IDENT_GENERIC: decl->define_decl.alias = symbol; + decl->type = symbol->type; return true; case DEFINE_TYPE_GENERIC: { @@ -3135,7 +3137,7 @@ static inline bool sema_analyse_define(SemaContext *c, Decl *decl) if (decl->define_decl.define_kind == DEFINE_IDENT_ALIAS) { Decl *symbol = sema_resolve_symbol(c, decl->define_decl.ident, decl->define_decl.path, decl->define_decl.span); - if (!decl_ok(symbol)) return false; + if (!sema_analyse_decl(c, symbol)) return false; decl->type = symbol->type; decl->define_decl.alias = symbol; return true; diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 4c147bf40..042bde988 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -776,10 +776,10 @@ static inline bool sema_expr_analyse_identifier(SemaContext *context, Type *to, } Decl *decl = sema_find_path_symbol(context, expr->identifier_expr.ident, expr->identifier_expr.path); + // Is this a broken decl? if (!decl_ok(decl)) return false; - // Rerun if we can't do inference. if (!decl) { @@ -7177,6 +7177,7 @@ static inline bool sema_expr_analyse_compound_literal(SemaContext *context, Expr { if (!sema_resolve_type_info(context, expr->expr_compound_literal.type_info)) return false; Type *type = expr->expr_compound_literal.type_info->type; + if (!sema_resolve_type_decl(context, type)) return false; if (type_is_optional(type)) { SEMA_ERROR(expr->expr_compound_literal.type_info, @@ -7652,7 +7653,7 @@ TokenType sema_splitpathref(const char *string, ArraySize len, Path **path_ref, if (!char_is_alphanum_(c)) return TOKEN_INVALID_TOKEN; hash = FNV1a(c, hash); } - TokenType type; + TokenType type = TOKEN_INVALID_TOKEN; *ident_ref = symtab_find(string, len, hash, &type); if (!*ident_ref) return TOKEN_IDENT; switch (type) diff --git a/src/compiler/sema_initializers.c b/src/compiler/sema_initializers.c index 657bb1afd..b8dfb872e 100644 --- a/src/compiler/sema_initializers.c +++ b/src/compiler/sema_initializers.c @@ -66,6 +66,7 @@ static inline void sema_not_enough_elements_error(Expr *initializer, int element */ static inline bool sema_expr_analyse_struct_plain_initializer(SemaContext *context, Decl *assigned, Expr *initializer) { + assert(assigned->resolve_status == RESOLVE_DONE); Expr **elements = initializer->initializer_list; Decl **members = assigned->strukt.members; MemberIndex size = (MemberIndex)vec_size(elements); diff --git a/src/version.h b/src/version.h index 0a50c1009..d95154cb6 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.510" \ No newline at end of file +#define COMPILER_VERSION "0.4.511" \ No newline at end of file