From 9d9cd528da07eaca5b7f006fd3c039c8c182ab10 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Tue, 1 Mar 2022 11:53:39 -0800 Subject: [PATCH] Added error for conflicting extension override methods --- IDEHelper/Compiler/BfModule.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 841e5073..9b083943 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -22261,6 +22261,8 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man { if ((methodDef->mIsOverride) && (mCurTypeInstance->mTypeDef->mIsCombinedPartial)) { + bool takeover = false; + mCurTypeInstance->mTypeDef->PopulateMemberSets(); BfMethodDef* nextMethod = NULL; BfMemberSetEntry* entry = NULL; @@ -22273,6 +22275,28 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man if (checkMethod == methodDef) continue; + if (checkMethod->mIsOverride) + { + auto checkMethodInstance = mCurTypeInstance->mMethodInstanceGroups[checkMethod->mIdx].mDefault; + if (checkMethodInstance == NULL) + continue; + if (checkMethodInstance->mIRFunction == prevFunc) + { + BfAstNode* refNode = methodDef->GetRefNode(); + if (auto propertyMethodDeclaration = methodDef->GetPropertyMethodDeclaration()) + refNode = propertyMethodDeclaration->mPropertyDeclaration->mVirtualSpecifier; + else if (auto methodDeclaration = methodDef->GetMethodDeclaration()) + refNode = methodDeclaration->mVirtualSpecifier; + + auto error = Fail(StrFormat("Conflicting extension override method '%s'", MethodToString(mCurMethodInstance).c_str()), refNode); + if (error != NULL) + mCompiler->mPassInstance->MoreInfo("See previous override", checkMethod->GetRefNode()); + + takeover = false; + break; + } + } + if (!checkMethod->mIsExtern) continue; auto checkMethodInstance = mCurTypeInstance->mMethodInstanceGroups[checkMethod->mIdx].mDefault; @@ -22281,8 +22305,11 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man if (!CompareMethodSignatures(checkMethodInstance, mCurMethodInstance)) continue; // Take over function - mCurMethodInstance->mIRFunction = prevFunc; + takeover = true; } + + if (takeover) + mCurMethodInstance->mIRFunction = prevFunc; if (!mCurMethodInstance->mIRFunction) {