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:
parent
51eaa6276f
commit
aa58c864f7
2 changed files with 20 additions and 21 deletions
|
@ -13961,8 +13961,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
||||||
BfBaseClassWalker baseClassWalker(walkFromType, walkToType, this);
|
BfBaseClassWalker baseClassWalker(walkFromType, walkToType, this);
|
||||||
|
|
||||||
bool isConstraintCheck = ((castFlags & BfCastFlags_IsConstraintCheck) != 0);
|
bool isConstraintCheck = ((castFlags & BfCastFlags_IsConstraintCheck) != 0);
|
||||||
|
|
||||||
BfType* operatorConstraintReturnType = NULL;
|
|
||||||
BfType* bestSelfType = NULL;
|
BfType* bestSelfType = NULL;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
@ -13986,14 +13985,24 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
||||||
// Try without arg
|
// Try without arg
|
||||||
args.mSize = 0;
|
args.mSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isConstraintCheck)
|
if (isConstraintCheck)
|
||||||
{
|
{
|
||||||
auto returnType = CheckOperator(checkType, operatorDef, typedVal, BfTypedValue());
|
auto returnType = CheckOperator(checkType, operatorDef, typedVal, BfTypedValue());
|
||||||
if (returnType != NULL)
|
if (returnType != NULL)
|
||||||
{
|
{
|
||||||
operatorConstraintReturnType = returnType;
|
auto result = BfTypedValue(mBfIRBuilder->GetFakeVal(), returnType);
|
||||||
methodMatcher.mBestMethodDef = operatorDef;
|
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
|
else
|
||||||
|
@ -14087,22 +14096,7 @@ 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
|
else
|
||||||
{
|
{
|
||||||
BfTypedValue result;
|
BfTypedValue result;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#pragma warning disable 168
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Tests
|
namespace Tests
|
||||||
|
@ -92,6 +94,9 @@ namespace Tests
|
||||||
|
|
||||||
Test.Assert(DoAdd(iNull, iNull) == 200);
|
Test.Assert(DoAdd(iNull, iNull) == 200);
|
||||||
Test.Assert(DoAdd(iNull, null) == null);
|
Test.Assert(DoAdd(iNull, null) == null);
|
||||||
|
|
||||||
|
String str = "Abc";
|
||||||
|
StringView? svn = str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue