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

Improved generic binding in mixins

Brian Fiete 3 жил өмнө
parent
commit
1183007a90

+ 8 - 3
IDEHelper/Compiler/BfExprEvaluator.cpp

@@ -3310,6 +3310,7 @@ BfType* BfExprEvaluator::BindGenericType(BfAstNode* node, BfType* bindType)
 	auto genericTypeBindings = mModule->mCurMethodState->GetRootMethodState()->mGenericTypeBindings;
 	auto methodInstance = mModule->mCurMethodInstance;
 
+	bool isMixinBind = false;
 	if (mModule->mCurMethodState->mMixinState != NULL)
 	{
 		auto mixinMethodInstance = mModule->mCurMethodState->mMixinState->mMixinMethodInstance;
@@ -3327,6 +3328,7 @@ BfType* BfExprEvaluator::BindGenericType(BfAstNode* node, BfType* bindType)
 				mModule->mContext->ProcessMethod(unspecMixinMethodInstance);
 			}
 
+			isMixinBind = true;
 			methodInstance = mixinMethodInstance;
 			genericTypeBindings = &unspecMixinMethodInstance->mMethodInfoEx->mGenericTypeBindings;
 		}
@@ -3334,6 +3336,9 @@ BfType* BfExprEvaluator::BindGenericType(BfAstNode* node, BfType* bindType)
 
 	if ((methodInstance->mIsUnspecialized) && (!methodInstance->mIsUnspecializedVariation))
 	{
+		if (isMixinBind)
+			return bindType;
+
 		if (!bindType->IsGenericParam())
 			return bindType;
 
@@ -9604,7 +9609,7 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
 					}
 				};
 
-				auto genericParamInstance = mModule->GetGenericParamInstance(genericParamTarget);
+				auto genericParamInstance = mModule->GetGenericParamInstance(genericParamTarget, true);
 				_HandleGenericParamInstance(genericParamInstance);
 				
 				// Check method generic constraints
@@ -10794,7 +10799,7 @@ void BfExprEvaluator::LookupQualifiedName(BfQualifiedNameNode* nameNode, bool ig
 	mResult = LookupField(nameNode->mRight, lookupVal, fieldName);
 	if ((!mResult) && (mPropDef == NULL) && (lookupType->IsGenericParam()))
 	{
-		auto genericParamInst = mModule->GetGenericParamInstance((BfGenericParamType*)lookupType);
+		auto genericParamInst = mModule->GetGenericParamInstance((BfGenericParamType*)lookupType, true);
 		SizedArray<BfTypeInstance*, 8> searchConstraints;
 		for (auto ifaceConstraint : genericParamInst->mInterfaceConstraints)
 		{			
@@ -10990,7 +10995,7 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
 
 	if ((!mResult) && (mPropDef == NULL) && (lookupType->IsGenericParam()))
 	{
-		auto genericParamInst = mModule->GetGenericParamInstance((BfGenericParamType*)lookupType);
+		auto genericParamInst = mModule->GetGenericParamInstance((BfGenericParamType*)lookupType, true);
 		SizedArray<BfTypeInstance*, 8> searchConstraints;
 		for (auto ifaceConstraint : genericParamInst->mInterfaceConstraints)
 		{			

+ 1 - 1
IDEHelper/Compiler/BfModule.h

@@ -1922,7 +1922,7 @@ public:
 	BfType* ResolveSelfType(BfType* type, BfType* selfType);
 	bool IsUnboundGeneric(BfType* type);
 	BfGenericParamInstance* GetGenericTypeParamInstance(int paramIdx);
-	BfGenericParamInstance* GetGenericParamInstance(BfGenericParamType* type);	
+	BfGenericParamInstance* GetGenericParamInstance(BfGenericParamType* type, bool checkMixinBind = false);
 	void GetActiveTypeGenericParamInstances(SizedArray<BfGenericParamInstance*, 4>& genericParamInstance);
 	BfGenericParamInstance* GetMergedGenericParamData(BfGenericParamType* type, BfGenericParamFlags& outFlags, BfType*& outTypeConstraint);
 	BfTypeInstance* GetBaseType(BfTypeInstance* typeInst);

+ 9 - 4
IDEHelper/Compiler/BfModuleTypeUtils.cpp

@@ -9353,12 +9353,12 @@ BfGenericParamInstance* BfModule::GetMergedGenericParamData(BfGenericParamType*
 	return genericParam;
 }
 
-BfGenericParamInstance* BfModule::GetGenericParamInstance(BfGenericParamType* type)
+BfGenericParamInstance* BfModule::GetGenericParamInstance(BfGenericParamType* type, bool checkMixinBind)
 {
 	if (type->mGenericParamKind == BfGenericParamKind_Method)
 	{
 		auto curGenericMethodInstance = mCurMethodInstance;
-		if ((mCurMethodState != NULL) && (mCurMethodState->mMixinState != NULL))
+		if ((checkMixinBind) && (mCurMethodState != NULL) && (mCurMethodState->mMixinState != NULL))
 			curGenericMethodInstance = mCurMethodState->mMixinState->mMixinMethodInstance;
 
 		if ((curGenericMethodInstance == NULL) || (curGenericMethodInstance->mMethodInfoEx == NULL) || (type->mGenericParamIdx >= curGenericMethodInstance->mMethodInfoEx->mGenericParams.mSize))
@@ -15681,8 +15681,7 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF
 				return;
 			}
 		}
-
-		//TEMPORARY
+		
 		if (genericParam->mGenericParamKind == BfGenericParamKind_Type)
 		{
 			auto curTypeInstance = mCurTypeInstance;
@@ -15696,6 +15695,12 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF
 		}
 
 		auto genericParamInstance = GetGenericParamInstance(genericParam);
+		if (genericParamInstance == NULL)
+		{
+			str += StrFormat("@M%d", genericParam->mGenericParamIdx);
+			return;
+		}
+
 		auto genericParamDef = genericParamInstance->GetGenericParamDef();
 		if (genericParamDef != NULL)
 			str += genericParamInstance->GetGenericParamDef()->mName;