From e6344c02b17e345cd7b5d4b976ff7865103cdd50 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Sun, 26 Jan 2020 06:28:04 -0800 Subject: [PATCH] Fixed default base ctor issues --- IDEHelper/Compiler/BfExprEvaluator.cpp | 17 ++++++++++++++++- IDEHelper/Compiler/BfModule.cpp | 18 +++++------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 7f0d1197..4d269e34 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -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(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; diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index ebd48f5c..fe9ae167 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -14408,8 +14408,7 @@ void BfModule::EmitCtorBody(bool& skipBody) (baseType->mTypeDef != mCompiler->mBfObjectTypeDef)) { // Try to find a ctor without any params first - BfMethodDef* matchedMethod = NULL; - bool hadCtorWithAllDefaults = false; + BfMethodDef* matchedMethod = NULL; for (int pass = 0; pass < 2; pass++) { @@ -14422,22 +14421,13 @@ 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; - + bool allowMethod = checkMethodDef->mProtection > BfProtection_Private; 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))