Fix for getting the correct generic type of consts. Fix of late initialization of structs using compound literals.

This commit is contained in:
Christoffer Lerno
2023-05-14 17:23:45 +02:00
parent 8eddbfb708
commit 353a072b75
5 changed files with 9 additions and 4 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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)

View File

@@ -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);

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.4.510"
#define COMPILER_VERSION "0.4.511"