From 2d4cc6d86ed85994ffbd3e12396cd0f5a7ba3b73 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Mon, 21 Sep 2020 07:51:36 -0700 Subject: [PATCH] Extension check refinements, more extension tests --- IDEHelper/Compiler/BfExprEvaluator.cpp | 3 ++ IDEHelper/Compiler/BfModuleTypeUtils.cpp | 3 +- IDEHelper/Compiler/BfResolvedTypeUtils.cpp | 36 ++----------------- IDEHelper/Tests/src/Extensions.bf | 40 +++++++++++++++++++--- 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index d1d57447..81f48094 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -212,6 +212,9 @@ void BfMethodMatcher::Init(/*SizedArrayImpl& arguments, */BfSized bool BfMethodMatcher::IsMemberAccessible(BfTypeInstance* typeInst, BfTypeDef* declaringType) { + if (!declaringType->mIsPartial) + return true; + if (mActiveTypeDef == NULL) mActiveTypeDef = mModule->GetActiveTypeDef(); diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index b3389f46..00d81eb9 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -2913,8 +2913,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy SetAndRestoreValue prevTypeRef(mContext->mCurTypeState->mCurFieldDef, fieldDef); bool populateChildType = !typeInstance->mTypeFailed; //bool populateChildType = true; - PopulateType(resolvedFieldType, populateChildType ? BfPopulateType_Data : BfPopulateType_Declaration); - BF_ASSERT(!typeInstance->mNeedsMethodProcessing); + PopulateType(resolvedFieldType, populateChildType ? BfPopulateType_Data : BfPopulateType_Declaration); if (populateChildType) { diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp index 5beaf461..2c7a675f 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp +++ b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp @@ -2093,9 +2093,7 @@ bool BfTypeInstance::IsTypeMemberIncluded(BfTypeDef* typeDef, BfTypeDef* activeT return true; if ((typeDef == NULL) || (typeDef == activeTypeDef)) return true; - if (typeDef->mTypeDeclaration == mTypeDef->mTypeDeclaration) - return true; - + // The combined type declaration is the root type declaration, it's implicitly included if (typeDef->mTypeDeclaration == mTypeDef->mTypeDeclaration) return true; @@ -2125,43 +2123,13 @@ bool BfTypeInstance::IsTypeMemberIncluded(BfTypeDef* typeDef, BfTypeDef* activeT genericArg = declGenericParam->mExternType; } - //auto genericType = mGenericTypeInfo->mTypeGenericArguments[genericIdx]; - if ((genericArg == NULL) || (!module->CheckGenericConstraints(BfGenericParamSource(), genericArg, NULL, declGenericParam))) return false; - - //if (!mModule->AreConstraintsSubset((*declConstraints)[genericIdx], (*activeConstraints)[genericIdx])) - //isSubset = false; } return true; } - /*else if ((mIsUnspecialized) && (activeTypeDef != NULL)) - { - auto subsetItr = genericExEntry->mConstraintSubsetMap.find(activeTypeDef); - if (subsetItr != genericExEntry->mConstraintSubsetMap.end()) - { - return subsetItr->second; - } - - auto declConstraints = &genericExEntry->mGenericParams; - auto activeConstraints = GetGenericParamsVector(activeTypeDef); - - bool isSubset = true; - for (int genericIdx = 0; genericIdx < (int)declConstraints->size(); genericIdx++) - { - if (!mModule->AreConstraintsSubset((*declConstraints)[genericIdx], (*activeConstraints)[genericIdx])) - isSubset = false; - } - - // We can't cache this because the meaning of the params may change, IE: TypeName<@M0> needs to consider the - // constraints of @M0 for each method it is checked against - if (!IsUnspecializedTypeVariation()) - genericExEntry->mConstraintSubsetMap[activeTypeDef] = isSubset; - - return isSubset; - }*/ - + return genericExEntry->mConstraintsPassed; } diff --git a/IDEHelper/Tests/src/Extensions.bf b/IDEHelper/Tests/src/Extensions.bf index fefa78b0..0b85013b 100644 --- a/IDEHelper/Tests/src/Extensions.bf +++ b/IDEHelper/Tests/src/Extensions.bf @@ -74,6 +74,26 @@ namespace Tests public int32 mB; } + class ClassB : IHashable + { + public int32 mA; + + public this(int32 a) + { + mA = a; + } + + public static bool operator==(ClassB lhs, ClassB rhs) + { + return lhs.mA == rhs.mA; + } + + public int GetHashCode() + { + return mA; + } + } + class TClassA where T : IDisposable { public int32 mA = 10; @@ -185,11 +205,23 @@ namespace Tests [Test] public static void TestDictionary() { - Dictionary dictLhs = scope .() {("Abc", 123), ("Def", 234) }; - Dictionary dictrhs = scope .() {(scope:: String("Abc"), 123), ("Def", 234) }; + Dictionary dictLhs = scope .() { ("Abc", 123), ("Def", 234) }; + Dictionary dictRhs = scope .() { (scope:: String("Abc"), 123), ("Def", 234) }; - Test.Assert(dictLhs == dictrhs); - Test.Assert(!LibA.LibA0.DictEquals(dictLhs, dictrhs)); + Test.Assert(dictLhs == dictRhs); + Test.Assert(!LibA.LibA0.DictEquals(dictLhs, dictRhs)); + + Dictionary[2] dictArrLhs = .(dictLhs, dictLhs); + Dictionary[2] dictArrRhs = .(dictRhs, dictRhs); + Test.Assert(dictArrLhs != dictArrRhs); + + Dictionary dictLhs2 = scope .() { (scope:: ClassB(111), 123) }; + Dictionary dictRhs2 = scope .() { (scope:: ClassB(111), 123) }; + Test.Assert(dictLhs2 == dictRhs2); + + Dictionary[2] dictArrLhs2 = .(dictLhs2, dictLhs2); + Dictionary[2] dictArrRhs2 = .(dictRhs2, dictRhs2); + Test.Assert(dictArrLhs2 == dictArrRhs2); } [Test]