From 947426b3846e49bcb88e13d1a793aae42f7ba262 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 10 Sep 2020 10:42:32 -0700 Subject: [PATCH] Fixed false circular data ref with self-refing field function typeref --- IDEHelper/Compiler/BfModuleTypeUtils.cpp | 16 ++++------ IDEHelper/Compiler/BfResolvedTypeUtils.cpp | 37 ++++++++++++---------- IDEHelper/Compiler/BfResolvedTypeUtils.h | 2 +- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index 82f8f909..f96bc707 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -6902,15 +6902,13 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy } } else if (resolvedTypeRef->IsDelegateFromTypeRef() || resolvedTypeRef->IsFunctionFromTypeRef()) - { + { auto delegateInfo = resolvedTypeRef->GetDelegateInfo(); - auto invokeMethod = GetDelegateInvokeMethod(resolvedTypeRef->ToTypeInstance()); - - AddDependency(invokeMethod->mReturnType, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference); - for (auto& param : invokeMethod->mParams) - { - AddDependency(param.mResolvedType, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference); - } + if (delegateInfo->mFunctionThisType != NULL) + AddDependency(delegateInfo->mFunctionThisType, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference); + AddDependency(delegateInfo->mReturnType, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference); + for (auto& param : delegateInfo->mParams) + AddDependency(param, mCurTypeInstance, BfDependencyMap::DependencyFlag_TypeReference); } BfTypeInstance* typeInstance = resolvedTypeRef->ToTypeInstance(); @@ -8864,7 +8862,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula bool failed = false; - auto returnType = ResolveTypeRef(delegateTypeRef->mReturnType); + auto returnType = ResolveTypeRef(delegateTypeRef->mReturnType, NULL, BfPopulateType_Declaration); if (returnType == NULL) returnType = GetPrimitiveType(BfTypeCode_Var); _CheckType(returnType); diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp index 326765d0..83110855 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp +++ b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp @@ -3681,16 +3681,19 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* { auto rhsDelegateType = BfNodeDynCastExact(rhs); if (rhsDelegateType == NULL) - return false; - BfDelegateInfo* lhsDelegateType = lhs->GetDelegateInfo(); - - BfMethodInstance* lhsInvokeMethodInstance = ctx->mModule->GetRawMethodInstanceAtIdx(lhs->ToTypeInstance(), 0, "Invoke"); + return false; + + BfDelegateInfo* lhsDelegateInfo = lhs->GetDelegateInfo(); + + auto lhsTypeInstance = lhs->ToTypeInstance(); + BfMethodDef* invokeMethodDef = lhsTypeInstance->mTypeDef->mMethods[0]; + BF_ASSERT(invokeMethodDef->mName == "Invoke"); bool rhsIsDelegate = rhsDelegateType->mTypeToken->GetToken() == BfToken_Delegate; if ((lhs->IsDelegate()) != rhsIsDelegate) return false; - if (!Equals(lhsInvokeMethodInstance->mReturnType, rhsDelegateType->mReturnType, ctx)) + if (!Equals(lhsDelegateInfo->mReturnType, rhsDelegateType->mReturnType, ctx)) return false; bool isMutating = true; @@ -3702,20 +3705,22 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* if ((param0->mNameNode != NULL) && (param0->mNameNode->Equals("this"))) { bool handled = false; - auto lhsThisType = lhsInvokeMethodInstance->GetParamType(-1); + auto lhsThisType = lhsDelegateInfo->mFunctionThisType; auto rhsThisType = ctx->mModule->ResolveTypeRef(param0->mTypeRef, BfPopulateType_Identity, (BfResolveTypeRefFlags)(BfResolveTypeRefFlag_NoWarnOnMut | BfResolveTypeRefFlag_AllowRef)); if (rhsThisType->IsRef()) - { - if (!lhsThisType->IsPointer()) + { + if (lhsThisType != rhsThisType->GetUnderlyingType()) + return false; + if (!invokeMethodDef->mIsMutating) return false; - if (lhsThisType->GetUnderlyingType() != rhsThisType->GetUnderlyingType()) - return false; } else { if (lhsThisType != rhsThisType) return false; + if ((invokeMethodDef->mIsMutating) && (lhsThisType->IsValueType())) + return false; } paramRefOfs = 1; @@ -3723,21 +3728,21 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* } if (!rhsIsDelegate) - { - if (lhsInvokeMethodInstance->mMethodDef->mIsStatic != (paramRefOfs == 0)) + { + if ((lhsDelegateInfo->mFunctionThisType == NULL) != (paramRefOfs == 0)) return false; } - if (lhsInvokeMethodInstance->GetParamCount() != (int)rhsDelegateType->mParams.size() - paramRefOfs) + if (lhsDelegateInfo->mParams.size() != (int)rhsDelegateType->mParams.size() - paramRefOfs) return false; - for (int paramIdx = 0; paramIdx < lhsInvokeMethodInstance->GetParamCount(); paramIdx++) + for (int paramIdx = 0; paramIdx < lhsDelegateInfo->mParams.size(); paramIdx++) { - if (!Equals(lhsInvokeMethodInstance->GetParamType(paramIdx), rhsDelegateType->mParams[paramIdx + paramRefOfs]->mTypeRef, ctx)) + if (!Equals(lhsDelegateInfo->mParams[paramIdx], rhsDelegateType->mParams[paramIdx + paramRefOfs]->mTypeRef, ctx)) return false; StringView rhsParamName; if (rhsDelegateType->mParams[paramIdx + paramRefOfs]->mNameNode != NULL) rhsParamName = rhsDelegateType->mParams[paramIdx + paramRefOfs]->mNameNode->ToStringView(); - if (lhsInvokeMethodInstance->GetParamName(paramIdx) != rhsParamName) + if (invokeMethodDef->mParams[paramIdx]->mName != rhsParamName) return false; } return true; diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.h b/IDEHelper/Compiler/BfResolvedTypeUtils.h index 563ba8ed..a7eedbf7 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.h +++ b/IDEHelper/Compiler/BfResolvedTypeUtils.h @@ -418,7 +418,7 @@ public: Array mDirectAllocNodes; BfType* mReturnType; BfType* mFunctionThisType; - Array mParams; + Array mParams; public: BfDelegateInfo()