mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +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);
|
||||
|
||||
bool isConstraintCheck = ((castFlags & BfCastFlags_IsConstraintCheck) != 0);
|
||||
|
||||
BfType* operatorConstraintReturnType = NULL;
|
||||
|
||||
BfType* bestSelfType = NULL;
|
||||
while (true)
|
||||
{
|
||||
|
@ -13986,14 +13985,24 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
|||
// Try without arg
|
||||
args.mSize = 0;
|
||||
}
|
||||
|
||||
|
||||
if (isConstraintCheck)
|
||||
{
|
||||
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
|
||||
|
@ -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
|
||||
{
|
||||
BfTypedValue result;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue