diff options
| author | SAJJA EASWAR <eshwarsajja20@gmail.com> | 2026-01-24 11:48:25 +0530 |
|---|---|---|
| committer | SAJJA EASWAR <eshwarsajja20@gmail.com> | 2026-01-24 11:48:25 +0530 |
| commit | f8e6dd33e93474024bd3678d5a98477254ab65a2 (patch) | |
| tree | 772bdf45530de6dfec64420193c5ea6e0841ab3e /src/parser/parser_struct.c | |
| parent | 22035400ed7b7fcda088a1a5b1ca6505b23bf63f (diff) | |
Fix generic struct pointer instantiation bug
Diffstat (limited to 'src/parser/parser_struct.c')
| -rw-r--r-- | src/parser/parser_struct.c | 14 |
1 files changed, 12 insertions, 2 deletions
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 |
