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

Pre-widened args for 'i32 = i8 + 100'

This commit is contained in:
Brian Fiete 2021-12-31 07:55:52 -05:00
parent 07a530c921
commit e7f079f611

View file

@ -20835,7 +20835,13 @@ void BfExprEvaluator::PerformBinaryOperation(BfExpression* leftExpression, BfExp
if ((binaryOp == BfBinaryOp_NullCoalesce) && (PerformBinaryOperation_NullCoalesce(opToken, leftExpression, rightExpression, leftValue, wantType, NULL)))
return;
rightValue = mModule->CreateValueFromExpression(rightExpression, wantType, (BfEvalExprFlags)((mBfEvalExprFlags & BfEvalExprFlags_InheritFlags) | BfEvalExprFlags_NoCast));
BfType* rightWantType = wantType;
if ((mExpectingType != NULL) && (wantType != NULL) && (mExpectingType->IsIntegral()) && (wantType->IsIntegral()) && (mExpectingType->mSize > wantType->mSize) &&
((binaryOp == BfBinaryOp_Add) || (binaryOp == BfBinaryOp_Subtract) || (binaryOp == BfBinaryOp_Multiply)))
rightWantType = mExpectingType;
rightValue = mModule->CreateValueFromExpression(rightExpression, rightWantType, (BfEvalExprFlags)((mBfEvalExprFlags & BfEvalExprFlags_InheritFlags) | BfEvalExprFlags_NoCast));
if ((rightWantType != wantType) && (rightValue.mType == rightWantType))
wantType = rightWantType;
if ((!leftValue) || (!rightValue))
return;
@ -21268,6 +21274,22 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
if (!forceLeftType)
{
bool handled = false;
if (leftValue.mType == rightValue.mType)
{
// All good
handled = true;
}
else if ((mExpectingType != NULL) &&
(mModule->CanCast(leftValue, mExpectingType, BfCastFlags_NoBox)) &&
(mModule->CanCast(rightValue, mExpectingType, BfCastFlags_NoBox)) &&
(!leftValue.mType->IsVar()) && (!rightValue.mType->IsVar()))
{
resultType = mExpectingType;
handled = true;
}
else
{
// If one of these is a constant that can be converted into a smaller type, then do that
if (rightValue.mValue.IsConst())
{
@ -21309,6 +21331,7 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
handled = true;
}
}
}
if (!handled)
{