Fix binary and/or with boolean values, now raising a warning

This commit is contained in:
drmortalwombat 2022-03-30 14:58:41 +02:00
parent a60f5a783f
commit 5a1ff68926
3 changed files with 10 additions and 1 deletions

View File

@ -21,6 +21,7 @@ enum ErrorID
EWARN_INDEX_OUT_OF_BOUNDS,
EWARN_SYNTAX,
EWARN_NOT_INTERRUPT_SAFE,
EWARN_BOOL_SHORTCUT,
EERR_GENERIC = 3000,
EERR_FILE_NOT_FOUND,

View File

@ -1542,6 +1542,14 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
dtype = TheUnsignedIntTypeDeclaration;
}
// Convert bool to char on binary operation
if (dtype->mType == DT_TYPE_BOOL)
{
if (exp->mToken == TK_BINARY_AND || exp->mToken == TK_BINARY_OR)
mErrors->Error(exp->mLocation, EWARN_BOOL_SHORTCUT, "Binary and/or operator used for boolean values, use logical operator ('&&' '||').");
dtype = TheUnsignedCharTypeDeclaration;
}
vl = CoerceType(proc, block, vl, dtype);
vr = CoerceType(proc, block, vr, dtype);

View File

@ -19085,7 +19085,7 @@ void NativeCodeBasicBlock::BuildPlacement(GrowingArray<NativeCodeBasicBlock*>& p
{
if (!mPlaced)
{
assert(mBranch != ASMIT_JMP || mIns.Size() > 0);
assert(mBranch != ASMIT_JMP || mIns.Size() > 0 || mTrueJump == this);
mPlaced = true;
mPlace = placement.Size();