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

Improved constraint check in CastToValue

This commit is contained in:
Brian Fiete 2022-07-11 10:54:04 -04:00
parent 51eaa6276f
commit aa58c864f7
2 changed files with 20 additions and 21 deletions

View file

@ -13962,7 +13962,6 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
bool isConstraintCheck = ((castFlags & BfCastFlags_IsConstraintCheck) != 0);
BfType* operatorConstraintReturnType = NULL;
BfType* bestSelfType = NULL;
while (true)
{
@ -13992,8 +13991,18 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
auto returnType = CheckOperator(checkType, operatorDef, typedVal, BfTypedValue());
if (returnType != NULL)
{
operatorConstraintReturnType = returnType;
methodMatcher.mBestMethodDef = operatorDef;
auto result = BfTypedValue(mBfIRBuilder->GetFakeVal(), returnType);
if (result)
{
if (result.mType != toType)
{
auto castedResult = CastToValue(srcNode, result, toType, (BfCastFlags)(castFlags | BfCastFlags_Explicit | BfCastFlags_NoConversionOperator), resultFlags);
if (castedResult)
return castedResult;
}
else
return result.mValue;
}
}
}
else
@ -14088,21 +14097,6 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
}
}
}
else if (isConstraintCheck)
{
auto result = BfTypedValue(mBfIRBuilder->GetFakeVal(), operatorConstraintReturnType);
if (result)
{
if (result.mType != toType)
{
auto castedResult = CastToValue(srcNode, result, toType, (BfCastFlags)(castFlags | BfCastFlags_Explicit | BfCastFlags_NoConversionOperator), resultFlags);
if (castedResult)
return castedResult;
}
else
return result.mValue;
}
}
else
{
BfTypedValue result;

View file

@ -1,3 +1,5 @@
#pragma warning disable 168
using System;
namespace Tests
@ -92,6 +94,9 @@ namespace Tests
Test.Assert(DoAdd(iNull, iNull) == 200);
Test.Assert(DoAdd(iNull, null) == null);
String str = "Abc";
StringView? svn = str;
}
}
}