diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 1fec1bafe8b24dbdcded94cee335d42627d4ddde..e6cb7629eea18a8aefafd867d5fe56306dc4c6b1 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -2861,6 +2861,11 @@ static bool CheckIfLiteralValueIsAppropriate(ETSChecker *checker, Type *type, ir } else if (number.IsDouble()) { return relation->IsIdenticalTo(checker->GlobalDoubleBuiltinType(), type); } + + if (relation->IsIdenticalTo(type, checker->GetGlobalTypesHolder()->GlobalCharBuiltinType())) { + auto charVal = number.GetValueAndCastTo(); + return charVal >= std::numeric_limits::min() && charVal <= std::numeric_limits::max(); + } return true; } diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index b76c779b5ae596684a2d710a8dac3be1938a5747..4f8a395e6cc4e19a6b055fbcb3efda6f2009e678 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -170,10 +170,15 @@ static Type *BinaryGetPromotedType(ETSChecker *checker, Type *left, Type *right, { Type *const unboxedL = TryConvertToPrimitiveType(checker, left); Type *const unboxedR = TryConvertToPrimitiveType(checker, right); + if (unboxedL == nullptr || unboxedR == nullptr) { return nullptr; } + if (left->IsETSEnumType() || left->IsETSEnumType()) { + return nullptr; + } + Type *typeL = left; Type *typeR = right; @@ -184,9 +189,6 @@ static Type *BinaryGetPromotedType(ETSChecker *checker, Type *left, Type *right, } if (!bothBoxed) { - if (unboxedL->IsETSEnumType() || unboxedR->IsETSEnumType()) { - return nullptr; - } if (!typeL->IsETSPrimitiveType()) { typeL = checker->MaybeUnboxType(typeL); } @@ -288,7 +290,7 @@ static bool TypeIsAppropriateForArithmetic(const checker::Type *type, ETSChecker static checker::Type *CheckBinaryOperatorForIntEnums(ETSChecker *checker, checker::Type *const leftType, checker::Type *const rightType) { - if (!leftType->IsETSEnumType() && !rightType->IsETSEnumType()) { + if (!leftType->IsETSEnumType() || !rightType->IsETSEnumType()) { return nullptr; } if (TypeIsAppropriateForArithmetic(leftType, checker) && TypeIsAppropriateForArithmetic(rightType, checker)) { @@ -643,11 +645,6 @@ bool ETSChecker::CheckValidEqualReferenceType(checker::Type *const leftType, che } } - if (FindOpArgsType(this, leftType, rightType, GetGlobalTypesHolder()->GlobalNumericBuiltinType()) && - (leftType->IsETSEnumType() || rightType->IsETSEnumType())) { - return true; - } - // 7.24.5 Enumeration Relational Operators return leftType->IsETSEnumType() == rightType->IsETSEnumType(); } @@ -751,10 +748,6 @@ static bool NonNumericTypesAreAppropriateForComparison(ETSChecker *checker, Type (leftType->IsETSStringType() && rightType->IsETSStringEnumType())) { return true; } - if ((leftType->IsETSPrimitiveType() && rightType->IsETSIntEnumType()) || - (leftType->IsETSIntEnumType() && rightType->IsETSPrimitiveType())) { - return true; - } return false; } @@ -780,7 +773,6 @@ std::tuple ETSChecker::CheckBinaryOperatorLessGreater(ir::Expres } auto const promotedType = BinaryGetPromotedType(this, leftType, rightType, !isEqualOp); - if (leftType->IsETSUnionType() || rightType->IsETSUnionType()) { return {GlobalETSBooleanBuiltinType(), CreateETSUnionType({MaybeBoxExpression(left), MaybeBoxExpression(right)})};