From f443c97f7026567c5e226251ad4cd4ee4301f663 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sat, 10 May 2025 13:40:36 +0200 Subject: [PATCH] Fix for default copy constructor on init calls --- oscar64/Parser.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index f128051..cc0b57d 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -2168,12 +2168,14 @@ Expression* Parser::ParseVarInitExpression(Expression* vexp, bool inner) if (dtype->mFlags & DTF_PURE_VIRTUAL) mErrors->Error(mScanner->mLocation, ERRR_INSTANTIATE_ABSTRACT_CLASS, "Cannot instantiate abstract class", dtype->mIdent); + Declaration* mtype = dtype->ToMutableType(); + + Expression* rexp = ParseRExpression(); + if (rexp->mDecType->IsSame(dtype)) + fcons = dtype->mCopyConstructor; + if (fcons) { - Declaration* mtype = dtype->ToMutableType(); - - Expression* rexp = ParseRExpression(); - Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT); cexp->mDecValue = fcons; cexp->mDecType = cexp->mDecValue->mBase; @@ -2225,6 +2227,15 @@ Expression* Parser::ParseVarInitExpression(Expression* vexp, bool inner) exp = nexp; } + else + { + rexp = CoerceExpression(rexp, dtype); + exp = new Expression(rexp->mLocation, EX_INITIALIZATION); + exp->mToken = TK_ASSIGN; + exp->mLeft = vexp; + exp->mRight = rexp; + exp->mDecType = dtype; + } } else { @@ -4608,6 +4619,12 @@ void Parser::ParseVariableInit(Declaration* ndec, Expression* pexp) if (ndec->mBase->mFlags & DTF_PURE_VIRTUAL) mErrors->Error(ndec->mLocation, ERRR_INSTANTIATE_ABSTRACT_CLASS, "Cannot instantiate abstract class", ndec->mIdent); + if (pexp && pexp->mType != EX_LIST) + { + if (pexp->mDecType->IsSame(ndec->mBase)) + fcons = ndec->mBase->mCopyConstructor; + } + if (fcons) { Declaration* mtype = ndec->mBase->ToMutableType();