From 7c44884cf08adc4b9edc28af7f0af36e81068f16 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 13 Feb 2020 12:29:06 -0800 Subject: [PATCH] Properly complains about hidden parameterless base ctor calling --- IDEHelper/Compiler/BfExprEvaluator.cpp | 17 +++++++++++++---- IDEHelper/Compiler/BfModule.cpp | 12 ++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 78b184ed..4324acae 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -5272,14 +5272,23 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu if (mModule->mParentNodeEntry != NULL) { + bool showCtorError = false; + 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); - } + showCtorError = true; } + + if (auto typerDecl = BfNodeDynCast(mModule->mParentNodeEntry->mNode)) + showCtorError = true; + + + if (showCtorError) + { + 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) diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index cd074629..7a307b7e 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -14446,7 +14446,7 @@ void BfModule::EmitCtorBody(bool& skipBody) BfMethodDef* matchedMethod = NULL; bool hadCtorWithAllDefaults = false; - bool isGenerated = methodDeclaration == NULL; + bool isHiddenGenerated = (methodDeclaration == NULL) && (methodDef->mProtection == BfProtection_Hidden); for (int pass = 0; pass < 2; pass++) { @@ -14461,7 +14461,7 @@ void BfModule::EmitCtorBody(bool& skipBody) { bool allowMethod = checkMethodDef->mProtection > BfProtection_Private; - if (isGenerated) + if (isHiddenGenerated) { // Allow calling of the default base ctor if it is implicitly defined if ((checkMethodDef->mMethodDeclaration == NULL) && (pass == 1) && (!hadCtorWithAllDefaults)) @@ -14474,7 +14474,7 @@ void BfModule::EmitCtorBody(bool& skipBody) { matchedMethod = checkMethodDef; } - else if (isGenerated) + else if (isHiddenGenerated) { if ((checkMethodDef->mParams[0]->mParamDeclaration != NULL) && (checkMethodDef->mParams[0]->mParamDeclaration->mInitializer != NULL)) hadCtorWithAllDefaults = true; @@ -14522,7 +14522,11 @@ void BfModule::EmitCtorBody(bool& skipBody) if (targetType != NULL) { - BfAutoParentNodeEntry autoParentNodeEntry(this, methodDeclaration); + BfAstNode* refNode = methodDeclaration; + if (refNode == NULL) + refNode = typeDef->mTypeDeclaration; + + BfAutoParentNodeEntry autoParentNodeEntry(this, refNode); auto autoComplete = mCompiler->GetAutoComplete(); auto wasCapturingMethodInfo = (autoComplete != NULL) && (autoComplete->mIsCapturingMethodMatchInfo);