diff --git a/core_codegen_c_language.cpp b/core_codegen_c_language.cpp index 814281e..9009220 100644 --- a/core_codegen_c_language.cpp +++ b/core_codegen_c_language.cpp @@ -1042,6 +1042,7 @@ compile_to_c_code() { genln("Type_Info *type_infos = (Type_Info[]){"); global_indent++; For_Named(pctx->all_types, t) { + if (t->kind == TYPE_POLYMORPH) continue; genln("{/*%Q*/.kind = %d, .size = %d, .align = %d, .is_unsigned = %s, .type = %d, ", typestring(t), (S32)t->kind, (S32)t->size, (S32)t->align, t->is_unsigned ? "true" : "false", t->type_id); switch (t->kind) { diff --git a/core_polymorph.cpp b/core_polymorph.cpp index 6db8659..7ca72aa 100644 --- a/core_polymorph.cpp +++ b/core_polymorph.cpp @@ -41,8 +41,13 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope, Array *replace, Arr if ((dst->flags & AST_TYPESPEC)) { For(*replace) { + assert(it->type == pctx->type_type); if (it->name == dst->intern_val) { - Breakpoint; + int it_index = replace->get_index(&it); + Ast_Call_Item *replacement = with[0][it_index]; + Ast_Atom *replacement_v = (Ast_Atom *)replacement->item; + assert(replacement_v->resolved_type == pctx->type_type); + dst = ast_create_copy(parent_scope, Ast_Atom, replacement_v); } } } @@ -289,6 +294,9 @@ Ast_Decl *get_or_instantiate_polymorph_type(Token *pos, Ast_Decl *poly, Arrayparent_scope, &poly->polymorph_parameters, ¶ms); + unset_flag(result->flags, AST_POLYMORPH); + result->type_val = type_incomplete(result); + result->polymorph_hash = hash; poly->polymorphs.add(result); } diff --git a/core_typechecking.cpp b/core_typechecking.cpp index ddaa15d..1645513 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -1577,8 +1577,9 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str // node->exprs = params Ast_Decl *instance = get_or_instantiate_polymorph_type(node->pos, poly, node->exprs, field_access_scope); - // type_complete(decl); - return {}; // operand_type(resolved_type); + resolve_decl(instance); + type_complete(instance->type_val); + return operand_type(instance->type_val); } /* @todo: @@ -1843,6 +1844,9 @@ resolve_decl(Ast_Decl *ast) { } ast->state = DECL_RESOLVED; - if (is_flag_set(ast->flags, AST_GLOBAL)) + bool is_polymorph = is_flag_set(ast->flags, AST_POLYMORPH); + bool is_global = is_flag_set(ast->flags, AST_GLOBAL); + if (is_global && !is_polymorph) { add(pctx->perm, &pctx->ordered_decls, ast); + } } diff --git a/examples/_polymorphism.core b/examples/_polymorphism.core index 3bcac37..27aec35 100644 --- a/examples/_polymorphism.core +++ b/examples/_polymorphism.core @@ -26,5 +26,7 @@ Array :: struct($T: Type) main :: (argc: int, argv: **char): int array: Array(int) + second_array: Array(int) + third_array: Array(int) return 0 \ No newline at end of file