1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +02:00

Allow comptime extern constraint typerefs

This commit is contained in:
Brian Fiete 2021-11-23 09:12:10 -08:00
parent 6fe2a7002a
commit 12a3ba937a
5 changed files with 54 additions and 18 deletions

View file

@ -1547,7 +1547,7 @@ bool BfMethodMatcher::InferFromGenericConstraints(BfMethodInstance* methodInstan
exprEvaluator.PerformUnaryOperation(NULL, checkOpConstraint.mUnaryOp, NULL, BfUnaryOpFlag_IsConstraintCheck);
if (exprEvaluator.mResult)
checkArgType = exprEvaluator.mResult.mType;
checkArgType = exprEvaluator.mResult.mType;
}
}
}
@ -1557,21 +1557,9 @@ bool BfMethodMatcher::InferFromGenericConstraints(BfMethodInstance* methodInstan
{
for (auto comptypeConstraint : genericParamInst->mComptypeConstraint)
{
BfConstraintState constraintSet;
constraintSet.mPrevState = mModule->mContext->mCurConstraintState;
constraintSet.mGenericParamInstance = genericParamInst;
constraintSet.mMethodInstance = methodInstance;
constraintSet.mMethodGenericArgsOverride = methodGenericArgs;
SetAndRestoreValue<BfConstraintState*> prevConstraintSet(mModule->mContext->mCurConstraintState, &constraintSet);
if (!mModule->CheckConstraintState(NULL))
return false;
SetAndRestoreValue<BfMethodInstance*> prevMethodInstance(mModule->mCurMethodInstance, methodInstance);
SetAndRestoreValue<BfTypeInstance*> prevTypeInstance(mModule->mCurTypeInstance, methodInstance->GetOwner());
SetAndRestoreValue<bool> prevIgnoreErrors(mModule->mIgnoreErrors, true);
checkArgType = mModule->ResolveTypeRef(comptypeConstraint);
checkArgType = mModule->ResolveGenericMethodTypeRef(comptypeConstraint, methodInstance, genericParamInst, methodGenericArgs);
if (checkArgType == NULL)
return false;
}
}
@ -2138,7 +2126,21 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
{
auto genericParam = methodInstance->mMethodInfoEx->mGenericParams[checkMethod->mGenericParams.size() + externConstraintIdx];
BF_ASSERT(genericParam->mExternType != NULL);
if (!mModule->CheckGenericConstraints(BfGenericParamSource(methodInstance), genericParam->mExternType, NULL, genericParam, genericArgumentsSubstitute, NULL))
auto externType = genericParam->mExternType;
BfTypeVector* externGenericArgumentsSubstitute = genericArgumentsSubstitute;
if (externType->IsVar())
{
auto& externConstraint = checkMethod->mExternalConstraints[externConstraintIdx];
if (externConstraint.mTypeRef != NULL)
{
externType = mModule->ResolveGenericMethodTypeRef(externConstraint.mTypeRef, methodInstance, genericParam, genericArgumentsSubstitute);
if (externType == NULL)
goto NoMatch;
}
}
if (!mModule->CheckGenericConstraints(BfGenericParamSource(methodInstance), externType, NULL, genericParam, externGenericArgumentsSubstitute, NULL))
goto NoMatch;
}