From db690b368f7e05b242f2e775f620f35ab0df5bc3 Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Tue, 20 Jan 2026 11:16:11 +0000 Subject: Smart derives... --- src/parser/parser_core.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/parser/parser_core.c') diff --git a/src/parser/parser_core.c b/src/parser/parser_core.c index c3c91fe..acab268 100644 --- a/src/parser/parser_core.c +++ b/src/parser/parser_core.c @@ -585,17 +585,19 @@ static ASTNode *generate_derive_impls(ParserContext *ctx, ASTNode *strct, char * ASTNode *fdef = find_struct_def(ctx, ft); if (fdef && fdef->type == NODE_ENUM) { - // Enum field: compare tags + // Enum field: compare tags (pointer access via auto-deref) sprintf(cmp, "self.%s.tag == other.%s.tag", fn, fn); } else if (fdef && fdef->type == NODE_STRUCT) { - // Struct field: use _eq function - sprintf(cmp, "%s__eq(&self.%s, other.%s)", ft, fn, fn); + // 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 + sprintf(cmp, "%s__eq(&self.%s, &other.%s)", ft, fn, fn); } else { - // Primitive or unknown: use == + // Primitive or unknown: use == (auto-deref) sprintf(cmp, "self.%s == other.%s", fn, fn); } strcat(body, cmp); @@ -610,7 +612,8 @@ static ASTNode *generate_derive_impls(ParserContext *ctx, ASTNode *strct, char * strcat(body, ";"); } code = xmalloc(4096 + 1024); - sprintf(code, "impl %s { fn eq(self, other: %s) -> bool { %s } }", name, name, body); + // Updated signature: other is a pointer T* + sprintf(code, "impl %s { fn eq(self, other: %s*) -> bool { %s } }", name, name, body); } else if (0 == strcmp(trait, "Debug")) { -- cgit v1.2.3