1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +02:00

Base ctor fixes

This commit is contained in:
Brian Fiete 2020-01-26 06:42:34 -08:00
parent e6344c02b1
commit 64cb1ab193
2 changed files with 20 additions and 4 deletions

View file

@ -5190,7 +5190,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu
} }
} }
if (error != NULL) if (error == NULL)
error = mModule->Fail(StrFormat("Not enough parameters specified, expected %d more.", methodInstance->GetParamCount() - paramIdx), refNode); error = mModule->Fail(StrFormat("Not enough parameters specified, expected %d more.", methodInstance->GetParamCount() - paramIdx), refNode);
if ((error != NULL) && (methodInstance->mMethodDef->mMethodDeclaration != NULL)) if ((error != NULL) && (methodInstance->mMethodDef->mMethodDeclaration != NULL))
mModule->mCompiler->mPassInstance->MoreInfo(StrFormat("See method declaration"), methodInstance->mMethodDef->GetRefNode()); mModule->mCompiler->mPassInstance->MoreInfo(StrFormat("See method declaration"), methodInstance->mMethodDef->GetRefNode());

View file

@ -14408,7 +14408,10 @@ void BfModule::EmitCtorBody(bool& skipBody)
(baseType->mTypeDef != mCompiler->mBfObjectTypeDef)) (baseType->mTypeDef != mCompiler->mBfObjectTypeDef))
{ {
// Try to find a ctor without any params first // Try to find a ctor without any params first
BfMethodDef* matchedMethod = NULL; BfMethodDef* matchedMethod = NULL;
bool hadCtorWithAllDefaults = false;
bool isGenerated = methodDeclaration == NULL;
for (int pass = 0; pass < 2; pass++) for (int pass = 0; pass < 2; pass++)
{ {
@ -14421,13 +14424,26 @@ void BfModule::EmitCtorBody(bool& skipBody)
while (checkMethodDef != NULL) while (checkMethodDef != NULL)
{ {
bool allowMethod = checkMethodDef->mProtection > BfProtection_Private; bool allowMethod = checkMethodDef->mProtection > BfProtection_Private;
if (isGenerated)
{
// Allow calling of the default base ctor if it is implicitly defined
if ((checkMethodDef->mMethodDeclaration == NULL) && (pass == 1) && (!hadCtorWithAllDefaults))
allowMethod = true;
}
if ((checkMethodDef->mMethodType == BfMethodType_Ctor) && (!checkMethodDef->mIsStatic) && (allowMethod)) if ((checkMethodDef->mMethodType == BfMethodType_Ctor) && (!checkMethodDef->mIsStatic) && (allowMethod))
{ {
if (checkMethodDef->mParams.size() == 0) if (checkMethodDef->mParams.size() == 0)
{ {
matchedMethod = checkMethodDef; matchedMethod = checkMethodDef;
} }
else if (isGenerated)
{
if ((checkMethodDef->mParams[0]->mParamDeclaration != NULL) && (checkMethodDef->mParams[0]->mParamDeclaration->mInitializer != NULL))
hadCtorWithAllDefaults = true;
}
} }
checkMethodDef = checkMethodDef->mNextWithSameName; checkMethodDef = checkMethodDef->mNextWithSameName;