From dcacf87d66e11ec05d1558f3228fc81dc219c55b Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 18 Nov 2020 12:07:18 -0800 Subject: [PATCH] Fixed ability to call GetType on an interface reference --- IDEHelper/Compiler/BfExprEvaluator.cpp | 8 ++++++-- IDEHelper/Tests/src/Interfaces.bf | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index ca94b830..a6125a8b 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -2233,8 +2233,12 @@ bool BfMethodMatcher::CheckType(BfTypeInstance* typeInstance, BfTypedValue targe if (baseType == NULL) { //TODO: Why were we doing the interface checking? - - if ((curTypeInst != mModule->mContext->mBfObjectType) && (!curTypeInst->IsInterface())) + if ((curTypeInst->IsInterface()) && (curTypeInst == target.mType)) + { + // When we are directly calling on interfaces rather than indirectly matching through binding + baseType = mModule->mContext->mBfObjectType; + } + else if ((curTypeInst != mModule->mContext->mBfObjectType) && (!curTypeInst->IsInterface())) { // This can happen for structs baseType = mModule->mContext->mBfObjectType; diff --git a/IDEHelper/Tests/src/Interfaces.bf b/IDEHelper/Tests/src/Interfaces.bf index 88b4c5de..da249202 100644 --- a/IDEHelper/Tests/src/Interfaces.bf +++ b/IDEHelper/Tests/src/Interfaces.bf @@ -127,6 +127,9 @@ namespace Tests Test.Assert(UseIA2((IFaceA)cba) == 60); Test.Assert(UseIA2(cc) == 70); Test.Assert(UseIA2(cca) == 70); + + IFaceA ifa = cba; + Test.Assert(ifa.GetType() == typeof(ClassB)); } ////