diff --git a/IDEHelper/Compiler/BfAst.cpp b/IDEHelper/Compiler/BfAst.cpp index 3ce3a77b..e6bc8e21 100644 --- a/IDEHelper/Compiler/BfAst.cpp +++ b/IDEHelper/Compiler/BfAst.cpp @@ -1559,20 +1559,23 @@ BfBinaryOp Beefy::BfAssignOpToBinaryOp(BfAssignmentOp assignmentOp) int Beefy::BfGetBinaryOpPrecendence(BfBinaryOp binOp) { switch (binOp) - { - case BfBinaryOp_LeftShift: - case BfBinaryOp_RightShift: - return 10; + { case BfBinaryOp_Multiply: case BfBinaryOp_Divide: - case BfBinaryOp_Modulus: - case BfBinaryOp_BitwiseAnd: - return 9; + case BfBinaryOp_Modulus: + return 13; case BfBinaryOp_Add: - case BfBinaryOp_Subtract: + case BfBinaryOp_Subtract: + return 12; + case BfBinaryOp_LeftShift: + case BfBinaryOp_RightShift: + return 11; + case BfBinaryOp_BitwiseAnd: + return 10; case BfBinaryOp_ExclusiveOr: + return 9; case BfBinaryOp_BitwiseOr: - return 8; + return 8; // "Range" inserted here if we were copying swift case BfBinaryOp_Is: case BfBinaryOp_As: diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index ff5b801e..25961724 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -12394,7 +12394,11 @@ void BfExprEvaluator::Visit(BfObjectCreateExpression* objCreateExpr) continue; } - auto elemAddr = mModule->CreateIndexedValue(resultType, addr, writeIdx); + BfIRValue elemAddr; + if (!resultType->IsValuelessType()) + elemAddr = mModule->CreateIndexedValue(resultType, addr, writeIdx); + else + elemAddr = mModule->mBfIRBuilder->GetFakeVal(); writeIdx++; dimWriteIdx++; @@ -20508,6 +20512,20 @@ void BfExprEvaluator::Visit(BfBinaryOperatorExpression* binOpExpr) } } + if ((binOpExpr->mOp == BfBinaryOp_LeftShift) || (binOpExpr->mOp == BfBinaryOp_RightShift)) + { + for (int side = 0; side < 2; side++) + { + if (auto innerBinOpExpr = BfNodeDynCast((side == 0) ? binOpExpr->mLeft : binOpExpr->mRight)) + { + if ((innerBinOpExpr->mOp == BfBinaryOp_Add) || (innerBinOpExpr->mOp == BfBinaryOp_Subtract)) + { + mModule->Warn(BfWarning_C4554_PossiblePrecedenceError, "Check operator precedence for possible error. Consider using parentheses to clarify precedence", innerBinOpExpr); + } + } + } + } + if (binOpExpr->mRight == NULL) { // We visit the children for autocompletion only diff --git a/IDEHelper/Compiler/BfSystem.h b/IDEHelper/Compiler/BfSystem.h index bbc97511..1846f7d6 100644 --- a/IDEHelper/Compiler/BfSystem.h +++ b/IDEHelper/Compiler/BfSystem.h @@ -1102,7 +1102,8 @@ enum BfWarning BfWarning_CS1030_PragmaWarning = 1030, BfWarning_BF4201_Only7Hex = 4201, BfWarning_BF4202_TooManyHexForInt = 4202, - BfWarning_BF4203_UnnecessaryDynamicCast = 4203 + BfWarning_BF4203_UnnecessaryDynamicCast = 4203, + BfWarning_C4554_PossiblePrecedenceError = 4554 }; class BfErrorBase