diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-20 11:16:11 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-20 11:16:11 +0000 |
| commit | db690b368f7e05b242f2e775f620f35ab0df5bc3 (patch) | |
| tree | c70d8e82bf81515e48b7bd2701595d6e62ce93e3 /src/parser/parser_core.c | |
| parent | f027a812707d68ca0690b7544175b9f302dd57ad (diff) | |
Smart derives...
Diffstat (limited to 'src/parser/parser_core.c')
| -rw-r--r-- | src/parser/parser_core.c | 13 |
1 files changed, 8 insertions, 5 deletions
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")) { |
