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

Disallow 'var' matching on failed conversion operators

This commit is contained in:
Brian Fiete 2022-02-16 09:29:00 -05:00
parent a8d06ea96d
commit 87d4a48a18

View file

@ -2177,6 +2177,13 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
BfCastFlags castFlags = ((mBfEvalExprFlags & BfEvalExprFlags_FromConversionOp) != 0) ? BfCastFlags_NoConversionOperator : BfCastFlags_None;
if ((mBfEvalExprFlags & BfEvalExprFlags_FromConversionOp_Explicit) != 0)
castFlags = (BfCastFlags)(castFlags | BfCastFlags_Explicit);
if ((mCheckReturnType != NULL) && (wantType->IsVar()))
{
// If we allowed this then it would allow too many matches (and allow conversion from any type during CastToValue)
goto NoMatch;
}
if (!mModule->CanCast(argTypedValue, wantType, castFlags))
{
if ((mAllowImplicitWrap) && (argTypedValue.mType->IsWrappableType()) && (mModule->GetWrappedStructType(argTypedValue.mType) == wantType))
@ -2228,6 +2235,11 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
if (mCheckReturnType != NULL)
{
auto returnType = methodInstance->mReturnType;
if (returnType->IsVar())
{
// If we allowed this then it would allow too many matches (and allow conversion to any type during CastToValue)
goto NoMatch;
}
if ((genericArgumentsSubstitute != NULL) && (returnType->IsUnspecializedType()))
{
auto resolvedType = mModule->ResolveGenericType(returnType, typeGenericArguments, genericArgumentsSubstitute, false);