From f8e6dd33e93474024bd3678d5a98477254ab65a2 Mon Sep 17 00:00:00 2001 From: SAJJA EASWAR Date: Sat, 24 Jan 2026 11:48:25 +0530 Subject: Fix generic struct pointer instantiation bug --- src/parser/parser_struct.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/parser/parser_struct.c') diff --git a/src/parser/parser_struct.c b/src/parser/parser_struct.c index 19bfd47..7dea30c 100644 --- a/src/parser/parser_struct.c +++ b/src/parser/parser_struct.c @@ -694,12 +694,14 @@ ASTNode *parse_struct(ParserContext *ctx, Lexer *l, int is_union) // Named use -> Composition (Add field, don't flatten) Token field_name = lexer_next(l); lexer_next(l); // eat : - char *field_type_str = parse_type(ctx, l); + Type *ft = parse_type_formal(ctx, l); + char *field_type_str = type_to_string(ft); expect(l, TOK_SEMICOLON, "Expected ;"); ASTNode *nf = ast_create(NODE_FIELD); nf->field.name = token_strdup(field_name); nf->field.type = field_type_str; + nf->type_info = ft; if (!h) { @@ -746,6 +748,12 @@ ASTNode *parse_struct(ParserContext *ctx, Lexer *l, int is_union) ASTNode *nf = ast_create(NODE_FIELD); nf->field.name = xstrdup(f->field.name); nf->field.type = xstrdup(f->field.type); + // Copy type info? Ideally deep copy or ref + // For now, we leave it NULL or shallow copy if needed, but mixins usually + // aren't generic params themselves in the same way. + // Let's shallow copy for safety if it exists. + nf->type_info = f->type_info; + if (!h) { h = nf; @@ -775,11 +783,13 @@ ASTNode *parse_struct(ParserContext *ctx, Lexer *l, int is_union) { Token f_name = lexer_next(l); expect(l, TOK_COLON, "Expected :"); - char *f_type = parse_type(ctx, l); + Type *ft = parse_type_formal(ctx, l); + char *f_type = type_to_string(ft); ASTNode *f = ast_create(NODE_FIELD); f->field.name = token_strdup(f_name); f->field.type = f_type; + f->type_info = ft; f->field.bit_width = 0; // Optional bit width: name: type : 3 -- cgit v1.2.3