summaryrefslogtreecommitdiff
path: root/src/parser/parser_core.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_core.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_core.c')
-rw-r--r--src/parser/parser_core.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/parser/parser_core.c b/src/parser/parser_core.c
index 5e685d7..1245a55 100644
--- a/src/parser/parser_core.c
+++ b/src/parser/parser_core.c
@@ -591,22 +591,34 @@ static ASTNode *generate_derive_impls(ParserContext *ctx, ASTNode *strct, char *
}
char cmp[256];
- ASTNode *fdef = find_struct_def(ctx, ft);
- if (fdef && fdef->type == NODE_ENUM)
+ // Detect pointer using type_info OR string check (fallback)
+ int is_ptr = 0;
+ if (f->type_info && f->type_info->kind == TYPE_POINTER)
{
- // Enum field: compare tags (pointer access via auto-deref)
+ is_ptr = 1;
+ }
+ // Fallback: check if type string ends with '*'
+ if (!is_ptr && ft && strchr(ft, '*'))
+ {
+ is_ptr = 1;
+ }
+
+ // Only look up struct def for non-pointer types
+ ASTNode *fdef = is_ptr ? NULL : find_struct_def(ctx, ft);
+
+ if (!is_ptr && fdef && fdef->type == NODE_ENUM)
+ {
+ // Enum field: compare tags
sprintf(cmp, "self.%s.tag == other.%s.tag", fn, fn);
}
- else if (fdef && fdef->type == NODE_STRUCT)
+ else if (!is_ptr && fdef && fdef->type == NODE_STRUCT)
{
- // Struct field: use _eq function, pass addresses
- // self.field is L-value, other.field is L-value (auto-deref from
- // pointer) We need addresses of them: &self.field, &other.field
+ // Struct field: use __eq function
sprintf(cmp, "%s__eq(&self.%s, &other.%s)", ft, fn, fn);
}
else
{
- // Primitive or unknown: use == (auto-deref)
+ // Primitive, POINTER, or unknown: use ==
sprintf(cmp, "self.%s == other.%s", fn, fn);
}
strcat(body, cmp);