1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

Changed ResolveSelfType to not require a type instance

This commit is contained in:
Brian Fiete 2022-04-30 08:10:57 -07:00
parent 1bacf5eee2
commit 717d6aa4cf
6 changed files with 71 additions and 61 deletions

View file

@ -369,7 +369,7 @@ bool BfGenericInferContext::InferGenericArgument(BfMethodInstance* methodInstanc
{
if ((genericParamInst->mTypeConstraint != NULL) && (genericParamInst->mTypeConstraint->IsDelegate()))
{
argType = mModule->ResolveGenericType(genericParamInst->mTypeConstraint, NULL, mCheckMethodGenericArguments);
argType = mModule->ResolveGenericType(genericParamInst->mTypeConstraint, NULL, mCheckMethodGenericArguments, mModule->mCurTypeInstance);
if (argType == NULL)
return true;
}
@ -855,7 +855,7 @@ void BfMethodMatcher::CompareMethods(BfMethodInstance* prevMethodInstance, BfTyp
bool paramWasUnspecialized = paramType->IsUnspecializedType();
if ((genericArgumentsSubstitute != NULL) && (paramWasUnspecialized))
{
paramType = mModule->ResolveGenericType(paramType, NULL, genericArgumentsSubstitute, allowSpecializeFail);
paramType = mModule->ResolveGenericType(paramType, NULL, genericArgumentsSubstitute, mModule->mCurTypeInstance, allowSpecializeFail);
paramType = mModule->FixIntUnknown(paramType);
}
if (paramType->IsConstExprValue())
@ -867,7 +867,7 @@ void BfMethodMatcher::CompareMethods(BfMethodInstance* prevMethodInstance, BfTyp
bool prevParamWasUnspecialized = prevParamType->IsUnspecializedType();
if ((prevGenericArgumentsSubstitute != NULL) && (prevParamWasUnspecialized))
{
prevParamType = mModule->ResolveGenericType(prevParamType, NULL, prevGenericArgumentsSubstitute, allowSpecializeFail);
prevParamType = mModule->ResolveGenericType(prevParamType, NULL, prevGenericArgumentsSubstitute, mModule->mCurTypeInstance, allowSpecializeFail);
prevParamType = mModule->FixIntUnknown(prevParamType);
}
if (prevParamType->IsConstExprValue())
@ -1359,7 +1359,7 @@ BfTypedValue BfMethodMatcher::ResolveArgTypedValue(BfResolvedArg& resolvedArg, B
bool success = false;
(*genericArgumentsSubstitute)[returnMethodGenericArgIdx] = mModule->GetPrimitiveType(BfTypeCode_None);
auto tryType = mModule->ResolveGenericType(origCheckType, NULL, genericArgumentsSubstitute);
auto tryType = mModule->ResolveGenericType(origCheckType, NULL, genericArgumentsSubstitute, mModule->mCurTypeInstance);
if (tryType != NULL)
{
auto inferredReturnType = mModule->CreateValueFromExpression(lambdaBindExpr, tryType, (BfEvalExprFlags)((mBfEvalExprFlags & BfEvalExprFlags_InheritFlags) | BfEvalExprFlags_NoCast | BfEvalExprFlags_InferReturnType | BfEvalExprFlags_NoAutoComplete));
@ -1369,7 +1369,7 @@ BfTypedValue BfMethodMatcher::ResolveArgTypedValue(BfResolvedArg& resolvedArg, B
if (((flags & BfResolveArgFlag_FromGenericParam) != 0) && (lambdaBindExpr->mNewToken == NULL))
{
auto resolvedType = mModule->ResolveGenericType(origCheckType, NULL, genericArgumentsSubstitute);
auto resolvedType = mModule->ResolveGenericType(origCheckType, NULL, genericArgumentsSubstitute, mModule->mCurTypeInstance);
if (resolvedType != NULL)
{
// Resolve for real
@ -1439,7 +1439,7 @@ BfTypedValue BfMethodMatcher::ResolveArgTypedValue(BfResolvedArg& resolvedArg, B
}
if ((genericArgumentsSubstitute != NULL) && (expectType->IsUnspecializedType()))
expectType = mModule->ResolveGenericType(expectType, NULL, genericArgumentsSubstitute, true);
expectType = mModule->ResolveGenericType(expectType, NULL, genericArgumentsSubstitute, mModule->mCurTypeInstance, true);
}
exprEvaluator.mExpectingType = expectType;
@ -1538,13 +1538,13 @@ bool BfMethodMatcher::InferFromGenericConstraints(BfMethodInstance* methodInstan
{
auto leftType = checkOpConstraint.mLeftType;
if ((leftType != NULL) && (leftType->IsUnspecializedType()))
leftType = mModule->ResolveGenericType(leftType, NULL, methodGenericArgs);
leftType = mModule->ResolveGenericType(leftType, NULL, methodGenericArgs, mModule->mCurTypeInstance);
if (leftType != NULL)
leftType = mModule->FixIntUnknown(leftType);
auto rightType = checkOpConstraint.mRightType;
if ((rightType != NULL) && (rightType->IsUnspecializedType()))
rightType = mModule->ResolveGenericType(rightType, NULL, methodGenericArgs);
rightType = mModule->ResolveGenericType(rightType, NULL, methodGenericArgs, mModule->mCurTypeInstance);
if (rightType != NULL)
rightType = mModule->FixIntUnknown(rightType);
@ -1857,7 +1857,7 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
if ((checkType != NULL) && (genericArgumentsSubstitute != NULL) && (checkType->IsUnspecializedType()))
{
attemptedGenericResolve = true;
checkType = mModule->ResolveGenericType(origCheckType, NULL, genericArgumentsSubstitute);
checkType = mModule->ResolveGenericType(origCheckType, NULL, genericArgumentsSubstitute, mModule->mCurTypeInstance);
}
if (wantType->IsUnspecializedType())
@ -2068,7 +2068,7 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
goto NoMatch;
auto paramsArrayType = methodInstance->GetParamType(paramIdx);
paramsArrayType = mModule->ResolveGenericType(paramsArrayType, NULL, genericArgumentsSubstitute);
paramsArrayType = mModule->ResolveGenericType(paramsArrayType, NULL, genericArgumentsSubstitute, mModule->mCurTypeInstance);
if (paramsArrayType == NULL)
goto NoMatch;
@ -2436,7 +2436,7 @@ NoMatch:
if (checkMethod->mMethodType == BfMethodType_Extension)
{
auto thisParam = methodInstance->GetParamType(0);
auto resolveThisParam = mModule->ResolveGenericType(thisParam, NULL, &mCheckMethodGenericArguments);
auto resolveThisParam = mModule->ResolveGenericType(thisParam, NULL, &mCheckMethodGenericArguments, mModule->mCurTypeInstance);
if (resolveThisParam == NULL)
return false;
if (!mModule->CanCast(mTarget, resolveThisParam,
@ -7400,8 +7400,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu
// Resolve `Self` types
if (wantType->IsUnspecializedTypeVariation())
{
SetAndRestoreValue<BfTypeInstance*> prevCurTypeInst(mModule->mCurTypeInstance, methodInstance->GetOwner());
wantType = mModule->ResolveGenericType(wantType, NULL, NULL);
wantType = mModule->ResolveSelfType(wantType, methodInstance->GetOwner());
}
}
@ -10119,7 +10118,7 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
if (result)
{
if (result.mType->IsRef())
result = mModule->RemoveRef(result);
result = mModule->RemoveRef(result);
}
PerformCallChecks(moduleMethodInstance.mMethodInstance, targetSrc);
@ -10219,8 +10218,7 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
if ((selfType != NULL) && (!selfType->IsInterface()))
{
SetAndRestoreValue<BfTypeInstance*> prevCurTypeInst(mModule->mCurTypeInstance, selfType->ToTypeInstance());
auto resolvedType = mModule->ResolveGenericType(result.mType, NULL, NULL);
auto resolvedType = mModule->ResolveSelfType(result.mType, selfType);
if ((resolvedType != NULL) && (resolvedType != result.mType))
result = mModule->GetDefaultTypedValue(resolvedType);
}
@ -12178,7 +12176,7 @@ bool BfExprEvaluator::CanBindDelegate(BfDelegateBindExpression* delegateBindExpr
{
if (!isGenericMatch)
return type;
auto fixedType = mModule->ResolveGenericType(type, NULL, methodGenericArgumentsSubstitute);
auto fixedType = mModule->ResolveGenericType(type, NULL, methodGenericArgumentsSubstitute, mModule->mCurTypeInstance);
if (fixedType != NULL)
return fixedType;
return (BfType*)mModule->GetPrimitiveType(BfTypeCode_Var);
@ -15952,7 +15950,7 @@ BfModuleMethodInstance BfExprEvaluator::GetSelectedMethod(BfAstNode* targetSrc,
if ((genericParam->mTypeConstraint != NULL) && (genericParam->mTypeConstraint->IsDelegate()))
{
// The only other option was to bind to a MethodRef
genericArg = mModule->ResolveGenericType(genericParam->mTypeConstraint, NULL, &methodMatcher.mBestMethodGenericArguments);
genericArg = mModule->ResolveGenericType(genericParam->mTypeConstraint, NULL, &methodMatcher.mBestMethodGenericArguments, mModule->mCurTypeInstance);
}
else
{
@ -16137,7 +16135,8 @@ BfModuleMethodInstance BfExprEvaluator::GetSelectedMethod(BfAstNode* targetSrc,
typeGenericArgs = &curTypeInst->mGenericTypeInfo->mTypeGenericArguments;
}
BfType* specializedReturnType = mModule->ResolveGenericType(typeUnspecMethodInstance->mReturnType, typeGenericArgs, &methodMatcher.mBestMethodGenericArguments);
BfType* specializedReturnType = mModule->ResolveGenericType(typeUnspecMethodInstance->mReturnType, typeGenericArgs, &methodMatcher.mBestMethodGenericArguments,
mModule->mCurTypeInstance);
if (specializedReturnType != NULL)
*overrideReturnType = specializedReturnType;
}
@ -22999,7 +22998,8 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
if (methodMatcher.CheckMethod(NULL, checkType, operatorDef, false))
{
auto rawMethodInstance = mModule->GetRawMethodInstance(checkType, operatorDef);
auto returnType = mModule->ResolveGenericType(rawMethodInstance->mReturnType, NULL, &methodMatcher.mBestMethodGenericArguments);
auto returnType = mModule->ResolveGenericType(rawMethodInstance->mReturnType, NULL, &methodMatcher.mBestMethodGenericArguments,
mModule->mCurTypeInstance);
if (returnType != NULL)
{
operatorConstraintReturnType = returnType;
@ -23048,7 +23048,8 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
if (methodMatcher.CheckMethod(NULL, checkType, oppositeOperatorDef, false))
{
auto rawMethodInstance = mModule->GetRawMethodInstance(checkType, oppositeOperatorDef);
auto returnType = mModule->ResolveGenericType(rawMethodInstance->mReturnType, NULL, &methodMatcher.mBestMethodGenericArguments);
auto returnType = mModule->ResolveGenericType(rawMethodInstance->mReturnType, NULL, &methodMatcher.mBestMethodGenericArguments,
mModule->mCurTypeInstance);
if (returnType != NULL)
{
operatorConstraintReturnType = returnType;

View file

@ -8302,7 +8302,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS
{
BfType* convCheckConstraint = genericParamInst->mTypeConstraint;
if ((convCheckConstraint->IsUnspecializedType()) && (methodGenericArgs != NULL))
convCheckConstraint = ResolveGenericType(convCheckConstraint, NULL, methodGenericArgs);
convCheckConstraint = ResolveGenericType(convCheckConstraint, NULL, methodGenericArgs, mCurTypeInstance);
if (convCheckConstraint == NULL)
return false;
if (((checkArgType->IsMethodRef()) || (checkArgType->IsFunction())) && (convCheckConstraint->IsDelegate()))
@ -8372,7 +8372,7 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS
{
BfType* convCheckConstraint = checkConstraint;
if (convCheckConstraint->IsUnspecializedType())
convCheckConstraint = ResolveGenericType(convCheckConstraint, NULL, methodGenericArgs);
convCheckConstraint = ResolveGenericType(convCheckConstraint, NULL, methodGenericArgs, mCurTypeInstance);
if (convCheckConstraint == NULL)
return false;
@ -8415,13 +8415,13 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS
{
auto leftType = checkOpConstraint.mLeftType;
if ((leftType != NULL) && (leftType->IsUnspecializedType()))
leftType = ResolveGenericType(leftType, NULL, methodGenericArgs);
leftType = ResolveGenericType(leftType, NULL, methodGenericArgs, mCurTypeInstance);
if (leftType != NULL)
leftType = FixIntUnknown(leftType);
auto rightType = checkOpConstraint.mRightType;
if ((rightType != NULL) && (rightType->IsUnspecializedType()))
rightType = ResolveGenericType(rightType, NULL, methodGenericArgs);
rightType = ResolveGenericType(rightType, NULL, methodGenericArgs, mCurTypeInstance);
if (rightType != NULL)
rightType = FixIntUnknown(rightType);
@ -10989,7 +10989,7 @@ StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodName
BfType* type = methodInst->mMethodInstanceGroup->mOwner;
if ((hasGenericArgs) && (type->IsUnspecializedType()))
type = ResolveGenericType(type, typeGenericArgs, methodGenericArgs);
type = ResolveGenericType(type, typeGenericArgs, methodGenericArgs, mCurTypeInstance);
if ((type == NULL) || (!type->IsUnspecializedTypeVariation()))
typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames;
if (allowResolveGenericParamNames)
@ -11003,7 +11003,7 @@ StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodName
if (allowResolveGenericParamNames)
typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames;
if ((hasGenericArgs) && (type->IsUnspecializedType()))
type = ResolveGenericType(type, typeGenericArgs, methodGenericArgs);
type = ResolveGenericType(type, typeGenericArgs, methodGenericArgs, mCurTypeInstance);
methodName += TypeToString(type, typeNameFlags);
};
@ -11174,7 +11174,7 @@ StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodName
}
if (type->IsUnspecializedType())
type = ResolveGenericType(type, NULL, methodGenericArgs);
type = ResolveGenericType(type, NULL, methodGenericArgs, mCurTypeInstance);
}
if ((methodGenericArgs == NULL) && (mCurMethodInstance == NULL) && (mCurTypeInstance == NULL))

View file

@ -1870,8 +1870,8 @@ public:
void EmitDeferredScopeCalls(bool useSrcPositions, BfScopeData* scope, BfIRBlock doneBlock = BfIRBlock());
void MarkScopeLeft(BfScopeData* scopeData, bool isNoReturn = false);
BfGenericParamType* GetGenericParamType(BfGenericParamKind paramKind, int paramIdx);
BfType* ResolveGenericType(BfType* unspecializedType, BfTypeVector* typeGenericArguments, BfTypeVector* methodGenericArguments, bool allowFail = false);
BfType* ResolveSelfType(BfType* type, BfTypeInstance* selfType);
BfType* ResolveGenericType(BfType* unspecializedType, BfTypeVector* typeGenericArguments, BfTypeVector* methodGenericArguments, BfType* selfType, bool allowFail = false);
BfType* ResolveSelfType(BfType* type, BfType* selfType);
bool IsUnboundGeneric(BfType* type);
BfGenericParamInstance* GetGenericTypeParamInstance(int paramIdx);
BfGenericParamInstance* GetGenericParamInstance(BfGenericParamType* type);

View file

@ -6450,7 +6450,7 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance)
auto iReturnType = ifaceMethodInst->mReturnType;
if (iReturnType->IsUnspecializedTypeVariation())
{
BfType* resolvedType = ResolveGenericType(iReturnType, NULL, NULL);
BfType* resolvedType = ResolveGenericType(iReturnType, NULL, NULL, mCurTypeInstance);
if (resolvedType != NULL)
iReturnType = resolvedType;
else
@ -8232,7 +8232,7 @@ BfTypeDef* BfModule::ResolveGenericInstanceDef(BfGenericInstanceTypeRef* generic
return NULL;
}
BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* typeGenericArguments, BfTypeVector* methodGenericArguments, bool allowFail)
BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* typeGenericArguments, BfTypeVector* methodGenericArguments, BfType* selfType, bool allowFail)
{
if (unspecializedType->IsGenericParam())
{
@ -8260,8 +8260,8 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty
return unspecializedType;
}
if ((unspecializedType->IsSelf()) && (mCurTypeInstance != NULL))
return mCurTypeInstance;
if ((unspecializedType->IsSelf()) && (selfType != NULL))
return selfType;
if (!unspecializedType->IsUnspecializedType())
{
@ -8271,12 +8271,12 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty
if (unspecializedType->IsUnknownSizedArrayType())
{
auto* arrayType = (BfUnknownSizedArrayType*)unspecializedType;
auto elementType = ResolveGenericType(arrayType->mElementType, typeGenericArguments, methodGenericArguments, allowFail);
auto elementType = ResolveGenericType(arrayType->mElementType, typeGenericArguments, methodGenericArguments, selfType, allowFail);
if (elementType == NULL)
return NULL;
if (elementType->IsVar())
return elementType;
auto sizeType = ResolveGenericType(arrayType->mElementCountSource, typeGenericArguments, methodGenericArguments, allowFail);
auto sizeType = ResolveGenericType(arrayType->mElementCountSource, typeGenericArguments, methodGenericArguments, selfType, allowFail);
if (sizeType == NULL)
return NULL;
if (sizeType->IsConstExprValue())
@ -8289,7 +8289,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty
if (unspecializedType->IsSizedArray())
{
auto* arrayType = (BfSizedArrayType*)unspecializedType;
auto elementType = ResolveGenericType(arrayType->mElementType, typeGenericArguments, methodGenericArguments, allowFail);
auto elementType = ResolveGenericType(arrayType->mElementType, typeGenericArguments, methodGenericArguments, selfType, allowFail);
if (elementType == NULL)
return NULL;
if (elementType->IsVar())
@ -8301,7 +8301,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty
if (unspecializedType->IsRef())
{
auto refType = (BfRefType*)unspecializedType;
auto elementType = ResolveGenericType(refType->GetUnderlyingType(), typeGenericArguments, methodGenericArguments, allowFail);
auto elementType = ResolveGenericType(refType->GetUnderlyingType(), typeGenericArguments, methodGenericArguments, selfType, allowFail);
if (elementType == NULL)
return NULL;
if (elementType->IsVar())
@ -8313,7 +8313,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty
if (unspecializedType->IsPointer())
{
auto ptrType = (BfPointerType*)unspecializedType;
auto elementType = ResolveGenericType(ptrType->GetUnderlyingType(), typeGenericArguments, methodGenericArguments, allowFail);
auto elementType = ResolveGenericType(ptrType->GetUnderlyingType(), typeGenericArguments, methodGenericArguments, selfType, allowFail);
if (elementType == NULL)
return NULL;
if (elementType->IsVar())
@ -8325,7 +8325,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty
if (unspecializedType->IsConcreteInterfaceType())
{
auto concreteType = (BfConcreteInterfaceType*)unspecializedType;
auto elementType = ResolveGenericType(concreteType->GetUnderlyingType(), typeGenericArguments, methodGenericArguments, allowFail);
auto elementType = ResolveGenericType(concreteType->GetUnderlyingType(), typeGenericArguments, methodGenericArguments, selfType, allowFail);
if (elementType == NULL)
return NULL;
auto elementTypeInstance = elementType->ToTypeInstance();
@ -8337,7 +8337,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty
if (unspecializedType->IsArray())
{
auto arrayType = (BfArrayType*)unspecializedType;
auto elementType = ResolveGenericType(arrayType->GetUnderlyingType(), typeGenericArguments, methodGenericArguments, allowFail);
auto elementType = ResolveGenericType(arrayType->GetUnderlyingType(), typeGenericArguments, methodGenericArguments, selfType, allowFail);
if (elementType == NULL)
return NULL;
if (elementType->IsVar())
@ -8361,7 +8361,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty
{
fieldNames.push_back(fieldInstance.GetFieldDef()->mName);
auto origGenericArg = fieldInstance.mResolvedType;
auto newGenericArg = ResolveGenericType(origGenericArg, typeGenericArguments, methodGenericArguments, allowFail);
auto newGenericArg = ResolveGenericType(origGenericArg, typeGenericArguments, methodGenericArguments, selfType, allowFail);
if (newGenericArg == NULL)
return NULL;
if (newGenericArg->IsVar())
@ -8400,7 +8400,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty
BfType* resolvedArg = unspecializedGenericTupleType->mGenericTypeInfo->mTypeGenericArguments[genericArgIdx];
if (resolvedArg->IsUnspecializedType())
{
resolvedArg = ResolveGenericType(resolvedArg, typeGenericArguments, methodGenericArguments, allowFail);
resolvedArg = ResolveGenericType(resolvedArg, typeGenericArguments, methodGenericArguments, selfType, allowFail);
if (resolvedArg == NULL)
return NULL;
if (resolvedArg->IsVar())
@ -8505,7 +8505,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty
bool failed = false;
bool hasTypeGenerics = false;
auto returnType = ResolveGenericType(unspecializedDelegateInfo->mReturnType, typeGenericArguments, methodGenericArguments, allowFail);
auto returnType = ResolveGenericType(unspecializedDelegateInfo->mReturnType, typeGenericArguments, methodGenericArguments, selfType, allowFail);
if (returnType == NULL)
return NULL;
@ -8518,7 +8518,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty
Array<BfType*> paramTypes;
for (auto param : unspecializedDelegateInfo->mParams)
{
auto paramType = ResolveGenericType(param, typeGenericArguments, methodGenericArguments, allowFail);
auto paramType = ResolveGenericType(param, typeGenericArguments, methodGenericArguments, selfType, allowFail);
if (paramType == NULL)
return NULL;
if (paramType->IsVar())
@ -8544,7 +8544,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty
BfType* resolvedArg = unspecializedGenericDelegateType->mGenericTypeInfo->mTypeGenericArguments[genericArgIdx];
if (resolvedArg->IsUnspecializedType())
{
resolvedArg = ResolveGenericType(resolvedArg, typeGenericArguments, methodGenericArguments, allowFail);
resolvedArg = ResolveGenericType(resolvedArg, typeGenericArguments, methodGenericArguments, selfType, allowFail);
if (resolvedArg == NULL)
return NULL;
if (resolvedArg->IsVar())
@ -8696,7 +8696,7 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty
{
if (genericArg->IsUnspecializedType())
{
auto resolvedArg = ResolveGenericType(genericArg, typeGenericArguments, methodGenericArguments, allowFail);
auto resolvedArg = ResolveGenericType(genericArg, typeGenericArguments, methodGenericArguments, selfType, allowFail);
if (resolvedArg == NULL)
return NULL;
if (resolvedArg->IsVar())
@ -8723,12 +8723,11 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty
return unspecializedType;
}
BfType* BfModule::ResolveSelfType(BfType* type, BfTypeInstance* selfType)
BfType* BfModule::ResolveSelfType(BfType* type, BfType* selfType)
{
if (!type->IsUnspecializedTypeVariation())
return type;
SetAndRestoreValue<BfTypeInstance*> prevCurTypeInst(mCurTypeInstance, selfType);
return ResolveGenericType(type, NULL, NULL);
return type;
return ResolveGenericType(type, NULL, NULL, selfType);
}
BfType* BfModule::ResolveType(BfType* lookupType, BfPopulateType populateType, BfResolveTypeRefFlags resolveFlags)
@ -11250,12 +11249,12 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
((type->IsDelegateFromTypeRef()) || (type->IsFunctionFromTypeRef())))
{
mContext->mResolvedTypes.RemoveEntry(resolvedEntry);
return ResolveGenericType(type, &genericArgs, NULL);
return ResolveGenericType(type, &genericArgs, NULL, mCurTypeInstance);
}
else if ((type != NULL) && (type->IsTuple()))
{
mContext->mResolvedTypes.RemoveEntry(resolvedEntry);
return ResolveGenericType(type, &genericArgs, NULL);
return ResolveGenericType(type, &genericArgs, NULL, mCurTypeInstance);
}
else if ((typeDef != NULL) && (typeDef->mTypeCode == BfTypeCode_TypeAlias))
{

View file

@ -5242,15 +5242,9 @@ String BfTypeUtils::TypeToString(BfAstNode* typeRefNode)
bool BfTypeUtils::TypeEquals(BfType* typeA, BfType* typeB, BfTypeInstance* selfType)
{
if (typeA->IsUnspecializedTypeVariation())
{
SetAndRestoreValue<BfTypeInstance*> prevCurTypeInst(selfType->mModule->mCurTypeInstance, selfType);
typeA = selfType->mModule->ResolveGenericType(typeA, NULL, NULL);
}
typeA = selfType->mModule->ResolveSelfType(typeA, selfType);
if (typeB->IsUnspecializedTypeVariation())
{
SetAndRestoreValue<BfTypeInstance*> prevCurTypeInst(selfType->mModule->mCurTypeInstance, selfType);
typeB = selfType->mModule->ResolveGenericType(typeB, NULL, NULL);
}
typeB = selfType->mModule->ResolveSelfType(typeB, selfType);
return typeA == typeB;
}

View file

@ -389,6 +389,22 @@ namespace Tests
}
}
class Test5
{
public Result<T> TryGetValue<T>() where T : IParseable
{
T val = default;
var s = T.Serialize(val);
return T.Deserialize(s);
}
}
interface IParseable
{
public static Result<Self> Deserialize(StringView value);
public static String Serialize(Self value);
}
[Test]
public static void TestDefaults()
{