Fix for default copy constructor on init calls

This commit is contained in:
drmortalwombat 2025-05-10 13:40:36 +02:00
parent 4837ceb73f
commit f443c97f70

View File

@ -2168,12 +2168,14 @@ Expression* Parser::ParseVarInitExpression(Expression* vexp, bool inner)
if (dtype->mFlags & DTF_PURE_VIRTUAL) if (dtype->mFlags & DTF_PURE_VIRTUAL)
mErrors->Error(mScanner->mLocation, ERRR_INSTANTIATE_ABSTRACT_CLASS, "Cannot instantiate abstract class", dtype->mIdent); 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) if (fcons)
{ {
Declaration* mtype = dtype->ToMutableType();
Expression* rexp = ParseRExpression();
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT); Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
cexp->mDecValue = fcons; cexp->mDecValue = fcons;
cexp->mDecType = cexp->mDecValue->mBase; cexp->mDecType = cexp->mDecValue->mBase;
@ -2225,6 +2227,15 @@ Expression* Parser::ParseVarInitExpression(Expression* vexp, bool inner)
exp = nexp; 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 else
{ {
@ -4608,6 +4619,12 @@ void Parser::ParseVariableInit(Declaration* ndec, Expression* pexp)
if (ndec->mBase->mFlags & DTF_PURE_VIRTUAL) if (ndec->mBase->mFlags & DTF_PURE_VIRTUAL)
mErrors->Error(ndec->mLocation, ERRR_INSTANTIATE_ABSTRACT_CLASS, "Cannot instantiate abstract class", ndec->mIdent); 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) if (fcons)
{ {
Declaration* mtype = ndec->mBase->ToMutableType(); Declaration* mtype = ndec->mBase->ToMutableType();