1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Fixed default base ctor issues

This commit is contained in:
Brian Fiete 2020-01-26 06:28:04 -08:00
parent c48c292f78
commit e6344c02b1
2 changed files with 21 additions and 14 deletions

View file

@ -5176,7 +5176,22 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu
if ((autoComplete != NULL) && (prevNode != NULL))
autoComplete->CheckEmptyStart(prevNode, wantType);
BfError* error = mModule->Fail(StrFormat("Not enough parameters specified, expected %d more.", methodInstance->GetParamCount() - paramIdx), refNode);
BfError* error = NULL;
if (mModule->mParentNodeEntry != NULL)
{
if (auto ctorDeclaration = BfNodeDynCast<BfConstructorDeclaration>(mModule->mParentNodeEntry->mNode))
{
if (ctorDeclaration->mInitializer == NULL)
{
error = mModule->Fail(StrFormat("No parameterless constructor is available for base class. Consider calling base constructor '%s'.",
mModule->MethodToString(methodInstance).c_str()), refNode);
}
}
}
if (error != NULL)
error = mModule->Fail(StrFormat("Not enough parameters specified, expected %d more.", methodInstance->GetParamCount() - paramIdx), refNode);
if ((error != NULL) && (methodInstance->mMethodDef->mMethodDeclaration != NULL))
mModule->mCompiler->mPassInstance->MoreInfo(StrFormat("See method declaration"), methodInstance->mMethodDef->GetRefNode());
failed = true;

View file

@ -14409,7 +14409,6 @@ void BfModule::EmitCtorBody(bool& skipBody)
{
// Try to find a ctor without any params first
BfMethodDef* matchedMethod = NULL;
bool hadCtorWithAllDefaults = false;
for (int pass = 0; pass < 2; pass++)
{
@ -14423,21 +14422,12 @@ void BfModule::EmitCtorBody(bool& skipBody)
while (checkMethodDef != NULL)
{
bool allowMethod = checkMethodDef->mProtection > BfProtection_Private;
// 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->mParams.size() == 0)
{
matchedMethod = checkMethodDef;
}
else if ((checkMethodDef->mParams[0]->mParamDeclaration != NULL) && (checkMethodDef->mParams[0]->mParamDeclaration->mInitializer != NULL))
{
if (pass == 0)
hadCtorWithAllDefaults = true;
}
}
checkMethodDef = checkMethodDef->mNextWithSameName;
@ -14481,6 +14471,8 @@ void BfModule::EmitCtorBody(bool& skipBody)
if (targetType != NULL)
{
BfAutoParentNodeEntry autoParentNodeEntry(this, methodDeclaration);
auto autoComplete = mCompiler->GetAutoComplete();
auto wasCapturingMethodInfo = (autoComplete != NULL) && (autoComplete->mIsCapturingMethodMatchInfo);
if ((autoComplete != NULL) && (ctorDeclaration != NULL) && (ctorDeclaration->mInitializer != NULL))