From 30fced09675acfd2b9ab6db6be8359a70d3f0402 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 18 Oct 2026 08:09:06 +0000 Subject: feat(operators): allow member assignment operator overloads Co-Authored-By: Claude Opus 5.5 --- lib/CodeGen/ConstructorGen.cc | 14 ++++++++++++++ lib/CodeGen/FunctionGen.cc | 6 ++++++ 2 files changed, 20 insertions(+) (limited to 'lib/CodeGen') diff --git a/lib/CodeGen/ConstructorGen.cc b/lib/CodeGen/ConstructorGen.cc index 4bf5568..9fc762c 100644 --- a/lib/CodeGen/ConstructorGen.cc +++ b/lib/CodeGen/ConstructorGen.cc @@ -142,6 +142,20 @@ void CodeGen::emitAssignment(const LValueInfo &Target, ExprAST *Expr, const Symb } return; } + if (Info && Info->IsClass) { + auto Resolution = resolveOperator(tok_assign, Info, getExprTypeInfo(Expr)); + if (Resolution.Ambiguous) { + reportError("Ambiguous assignment operator"); + return; + } + if (const FuncSig *Sig = Resolution.Signature) { + if (!checkOperatorAccess(*Sig)) return; + std::vector Args = {Target.Addr}; + if (marshalCallArgs(*Sig, std::vector{Expr}, DiagnosticLine, Args)) + FuncGen->emitCall(*Sig, Args); + return; + } + } Value *Val = emitCoercedExpr(Expr, Info); if (Val) Builder->CreateStore(Val, Target.Addr); } diff --git a/lib/CodeGen/FunctionGen.cc b/lib/CodeGen/FunctionGen.cc index 37df8ff..1f7bc2b 100644 --- a/lib/CodeGen/FunctionGen.cc +++ b/lib/CodeGen/FunctionGen.cc @@ -132,6 +132,12 @@ Function *FunctionGen::emitPrototype(PrototypeAST *Proto) { return nullptr; } } + if (Proto->getOperator() == tok_assign && + (Proto->getOwnerClass().empty() || !Proto->isOverload() || + !sameIdentifier(Proto->getReturnType(), "VOID"))) { + reportError("Assignment operator must be an OVERLOAD member PROCEDURE"); + return nullptr; + } if (int Op = Proto->getOperator()) { size_t Count = Proto->getParams().size() + !Proto->getOwnerClass().empty(); bool ValidCount = Op == '-' ? Count == 1 || Count == 2 -- cgit v1.3.1-4-g156e