summaryrefslogtreecommitdiff
path: root/src/parser/parser_struct.c
diff options
context:
space:
mode:
authorZuhaitz <zuhaitz.zechhub@gmail.com>2026-01-25 23:23:43 +0000
committerGitHub <noreply@github.com>2026-01-25 23:23:43 +0000
commitb568f67d75553bbecd2cadc4d61b330b8aea2ad2 (patch)
tree93de523967424146ba2b4ccb0f728c47cdbe2251 /src/parser/parser_struct.c
parent18b0932249b0df8ddea159ba187cb9c3587197da (diff)
parent59951529ba67d3316a01afd45808c1b20b20c1e1 (diff)
Merge pull request #109 from iryuken/main
Fix generic struct pointer instantiation bug #105
Diffstat (limited to 'src/parser/parser_struct.c')
-rw-r--r--src/parser/parser_struct.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/parser/parser_struct.c b/src/parser/parser_struct.c
index e776bb8..17d8e93 100644
--- a/src/parser/parser_struct.c
+++ b/src/parser/parser_struct.c
@@ -740,12 +740,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)
{
@@ -792,6 +794,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;
@@ -821,11 +829,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