From fdf882d71cff18504ce1b53d5bf270b3a37e9e81 Mon Sep 17 00:00:00 2001 From: Ben Harshbarger Date: Tue, 10 Dec 2024 15:23:51 -0800 Subject: [PATCH] Replace 'collectFields' with 'fieldsForTypeDecl' Signed-off-by: Ben Harshbarger --- frontend/lib/resolution/default-functions.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/frontend/lib/resolution/default-functions.cpp b/frontend/lib/resolution/default-functions.cpp index f1486bd94737..7812a16f2a68 100644 --- a/frontend/lib/resolution/default-functions.cpp +++ b/frontend/lib/resolution/default-functions.cpp @@ -447,19 +447,22 @@ const BuilderResult& buildInitEquals(Context* context, ID typeID) { AstList stmts; - std::vector fields; - for (auto d : typeDecl->decls()) { - collectFields(d, fields); - } + auto ct = initialTypeForTypeDecl(context, typeID)->getCompositeType(); - for (auto field : fields) { + // attempt to resolve the fields + DefaultsPolicy defaultsPolicy = DefaultsPolicy::IGNORE_DEFAULTS; + const ResolvedFields& rf = fieldsForTypeDecl(context, ct, + defaultsPolicy, + /* syntaxOnly */ true); + for (int i = 0; i < rf.numFields(); i++) { + auto name = rf.fieldName(i); // Create 'this.field = other.field;' statement owned lhs = Dot::build(builder, dummyLoc, Identifier::build(builder, dummyLoc, USTR("this")), - field->name()); + name); owned rhs = Dot::build(builder, dummyLoc, Identifier::build(builder, dummyLoc, otherName), - field->name()); + name); owned assign = OpCall::build(builder, dummyLoc, USTR("="), std::move(lhs), std::move(rhs)); stmts.push_back(std::move(assign));