2
0
Эх сурвалжийг харах

Fixed ability to call GetType on an interface reference

Brian Fiete 4 жил өмнө
parent
commit
dcacf87d66

+ 6 - 2
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;

+ 3 - 0
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));
 		}
 
 		////