diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index cbe2c38d4ec82f65b2addbc0f7694aed02f89501..ffca77c72371c9089c619d3e3df4556614f35906 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -48,20 +48,27 @@ static void LogOperatorCannotBeApplied(ETSChecker *checker, BinaryArithmOperands LogOperatorCannotBeApplied(checker, ops.expr->OperatorType(), ops.typeL, ops.typeR, ops.expr->Start()); } -static inline void RepairTypeErrorsInOperands(Type **left, Type **right) +static void RepairTypeErrorsInOperands(Type **left, Type **right, ir::Expression *exprL = nullptr, + ir::Expression *exprR = nullptr) { if (IsTypeError(*left)) { *left = *right; + if (exprL != nullptr) { + exprL->SetTsType(*left); + } } if (IsTypeError(*right)) { *right = *left; + if (exprR != nullptr) { + exprR->SetTsType(*right); + } } } static inline BinaryArithmOperands RepairTypeErrorsInOperands(BinaryArithmOperands const &ops) { BinaryArithmOperands res = ops; - RepairTypeErrorsInOperands(&res.typeL, &res.typeR); + RepairTypeErrorsInOperands(&res.typeL, &res.typeR, res.expr->Left(), res.expr->Right()); RepairTypeErrorsInOperands(&res.reducedL, &res.reducedR); return res; } @@ -329,7 +336,7 @@ checker::Type *ETSChecker::CheckBinaryOperatorMulDivMod( auto [leftType, rightType, unboxedL, unboxedR] = types; // Try to handle errors on a lower level - RepairTypeErrorsInOperands(&leftType, &rightType); + RepairTypeErrorsInOperands(&leftType, &rightType, left, right); RepairTypeErrorsInOperands(&unboxedL, &unboxedR); if (leftType->IsTypeError()) { // both are errors return GlobalTypeError(); @@ -397,7 +404,7 @@ checker::Type *ETSChecker::CheckBinaryOperatorPlus( auto [leftType, rightType, unboxedL, unboxedR] = types; // Try to handle errors on a lower level - RepairTypeErrorsInOperands(&leftType, &rightType); + RepairTypeErrorsInOperands(&leftType, &rightType, left, right); RepairTypeErrorsInOperands(&unboxedL, &unboxedR); if (leftType->IsTypeError()) { // both are errors return GlobalTypeError(); @@ -509,7 +516,7 @@ checker::Type *ETSChecker::CheckBinaryOperatorBitwise( auto [left, right, operationType, pos] = op; auto [leftType, rightType, unboxedL, unboxedR] = types; - RepairTypeErrorsInOperands(&leftType, &rightType); + RepairTypeErrorsInOperands(&leftType, &rightType, left, right); RepairTypeErrorsInOperands(&unboxedL, &unboxedR); if (leftType->IsTypeError()) { // both are errors return GlobalTypeError(); @@ -555,7 +562,7 @@ checker::Type *ETSChecker::CheckBinaryOperatorLogical(ir::Expression *left, ir:: checker::Type *leftType, checker::Type *rightType, Type *unboxedL, Type *unboxedR) { - RepairTypeErrorsInOperands(&leftType, &rightType); + RepairTypeErrorsInOperands(&leftType, &rightType, left, right); RepairTypeErrorsInOperands(&unboxedL, &unboxedR); if (leftType->IsTypeError()) { // both are errors return GlobalTypeError(); @@ -773,7 +780,7 @@ std::tuple ETSChecker::CheckBinaryOperatorLessGreater(ir::Expres checker::Type *leftType, checker::Type *rightType, Type *unboxedL, Type *unboxedR) { - RepairTypeErrorsInOperands(&leftType, &rightType); + RepairTypeErrorsInOperands(&leftType, &rightType, left, right); RepairTypeErrorsInOperands(&unboxedL, &unboxedR); if (leftType->IsTypeError()) { // both are errors return {GlobalETSBooleanBuiltinType(), GlobalTypeError()}; @@ -1152,12 +1159,6 @@ std::tuple ETSChecker::CheckArithmeticOperations( if (tsType->IsETSPrimitiveType()) { tsType = MaybeBoxType(tsType); } - if (left->TsType()->IsTypeError()) { - left->SetTsType(tsType); - } - if (right->TsType()->IsTypeError()) { - right->SetTsType(tsType); - } return {tsType, tsType}; }