diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index c80085be..10875f94 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -69,11 +69,21 @@ BfBaseClassWalker::BfBaseClassWalker(BfType* typeA, BfType* typeB, BfModule* mod AddConstraints(typeA, module->GetGenericParamInstance((BfGenericParamType*)typeA)); } + if ((typeA != NULL) && (typeA->IsInterface())) + { + AddInterfaces(typeA, typeA->ToTypeInstance()); + } + if ((typeB != NULL) && (typeB->IsGenericParam())) { mMayBeFromInterface = true; AddConstraints(typeB, module->GetGenericParamInstance((BfGenericParamType*)typeB)); } + + if ((typeB != NULL) && (typeB->IsInterface())) + { + AddInterfaces(typeB, typeB->ToTypeInstance()); + } } /*BfBaseClassWalker::BfBaseClassWalker(BfTypeInstance* typeA, BfTypeInstance* typeB) @@ -95,6 +105,8 @@ void BfBaseClassWalker::AddConstraints(BfType* srcType, BfGenericParamInstance* { auto typeInst = genericParam->mTypeConstraint->ToTypeInstance(); { + if (typeInst->IsInterface()) + AddInterfaces(srcType, typeInst->ToTypeInstance()); Entry entry(srcType, typeInst); if ((typeInst != NULL) && (!mManualList.Contains(entry))) mManualList.Add(entry); @@ -103,12 +115,24 @@ void BfBaseClassWalker::AddConstraints(BfType* srcType, BfGenericParamInstance* for (auto typeInst : genericParam->mInterfaceConstraints) { + if (typeInst->IsInterface()) + AddInterfaces(srcType, typeInst->ToTypeInstance()); Entry entry(srcType, typeInst); if ((typeInst != NULL) && (!mManualList.Contains(entry))) mManualList.Add(entry); } } +void BfBaseClassWalker::AddInterfaces(BfType* srcType, BfTypeInstance* typeInst) +{ + for (auto ifaceEntry : typeInst->mInterfaces) + { + Entry entry(srcType, ifaceEntry.mInterfaceType); + if ((typeInst != NULL) && (!mManualList.Contains(entry))) + mManualList.Add(entry); + } +} + BfBaseClassWalker::Entry BfBaseClassWalker::Next() { if (!mManualList.IsEmpty()) diff --git a/IDEHelper/Compiler/BfExprEvaluator.h b/IDEHelper/Compiler/BfExprEvaluator.h index bcc4d71a..dde639e2 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.h +++ b/IDEHelper/Compiler/BfExprEvaluator.h @@ -313,6 +313,7 @@ public: BfBaseClassWalker(); BfBaseClassWalker(BfType* typeA, BfType* typeB, BfModule* module); void AddConstraints(BfType* srcType, BfGenericParamInstance* genericParam); + void AddInterfaces(BfType* srcType, BfTypeInstance* typeInst); public: Entry Next(); diff --git a/IDEHelper/Tests/src/Interfaces.bf b/IDEHelper/Tests/src/Interfaces.bf index b65a770b..475f065d 100644 --- a/IDEHelper/Tests/src/Interfaces.bf +++ b/IDEHelper/Tests/src/Interfaces.bf @@ -413,6 +413,25 @@ namespace Tests } } + public interface IAdd + { + static Self operator+(Self a, Self b); + } + + public interface IAdd2 : IAdd + { + } + + public static void MyFunction(T a, T b) where T : IAdd + { + T sum = a + b; + } + + public static void MyFunction2(T a, T b) where T : IAdd2 + { + T sum = a + b; + } + [Test] public static void TestDefaults() {