We are working! POLYMORPHS There was an error where we have to reconstruct exact

typespec from type. This means we will probably have problems with namespaces!!
This commit is contained in:
Krzosa Karol
2023-04-02 15:07:47 +02:00
parent c4b27bf604
commit 41d2baa56b
5 changed files with 30 additions and 10 deletions

View File

@@ -70,7 +70,16 @@ Ast_Expr *create_typespec_from_type(Token *pos, Ast_Scope *parent_scope, Ast_Typ
case TYPE_UNION:
case TYPE_ENUM: {
Ast_Decl *decl = (Ast_Decl *)type->ast;
result = ast_ident(pos, decl->name);
// @warning:
// Can we do this differently?
// WE MIGHT HAVE PROBLEM WITH NAMESPACES in the future!!!
if (decl->flags & AST_POLYMORPH_INSTANCE) {
Ast_Atom *ident = ast_ident(pos, decl->name);
ident->parent_scope = parent_scope;
result = ast_call(pos, ident, decl->instantiation_call_items);
}
else result = ast_ident(pos, decl->name);
} break;
}
result->parent_scope = parent_scope;
@@ -362,6 +371,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope, Array<Ast_Decl *> *replace, Arr
assert(result);
unset_flag(result->flags, AST_POLYMORPH | AST_PARENT_POLYMORPH);
set_flag(result->flags, AST_POLYMORPH_INSTANCE);
return result;
}
@@ -399,8 +409,9 @@ Ast_Decl *get_or_instantiate_polymorph_type(Token *pos, Ast_Decl *poly, Array<As
if (!result) {
result = (Ast_Decl *)ast_copy(poly, poly->parent_scope, &poly->polymorph_parameters, &params);
if (poly->kind == AST_STRUCT || poly->kind == AST_UNION) result->type_val = type_incomplete(result);
result->type_val = type_incomplete(result);
result->polymorph_hash = hash;
result->instantiation_call_items = params.tight_copy(pctx->perm);
assert(result->di != poly->di);
result->unique_name = get_unique_name_for_decl(result);
@@ -410,7 +421,7 @@ Ast_Decl *get_or_instantiate_polymorph_type(Token *pos, Ast_Decl *poly, Array<As
}
resolve_decl(result);
if (poly->kind == AST_STRUCT || poly->kind == AST_UNION) type_complete(result->type_val);
type_complete(result->type_val);
return result;
}
@@ -436,6 +447,7 @@ Ast_Decl *get_or_instantiate_polymorph_lambda(Token *pos, Ast_Decl *poly, Array<
Operand op = resolve_expr(it->item, AST_CANT_BE_NULL, 0, field_access_scope);
try_converting_untyped_to_default_type(&op);
try_propagating_resolved_type_to_untyped_literals(it->item, op.type);
// type_complete(op.type);
assert(it->item->resolved_type == op.type);
hash = hash_mix(hash, hash_ptr(op.type));