diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index cc7e14a1bbeb453976419d06e0a851947f1647bc..1f0e7ff48397e56b63e5512a6e31c638b7d77c15 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -91,10 +91,13 @@ bool ETSChecker::CheckIfNumeric(Type *type) return false; } if (type->IsETSPrimitiveType()) { - return type->HasTypeFlag(TypeFlag::ETS_CONVERTIBLE_TO_NUMERIC); + // NOTE(rsipka): Deprecated operations on 'char' #28006, it should be removed from ETS_CONVERTIBLE_TO_NUMERIC + return type->HasTypeFlag(TypeFlag::ETS_CONVERTIBLE_TO_NUMERIC) && type->HasTypeFlag(TypeFlag::CHAR); } auto *unboxed = MaybeUnboxInRelation(type); - return (unboxed != nullptr) && unboxed->HasTypeFlag(TypeFlag::ETS_CONVERTIBLE_TO_NUMERIC); + // NOTE(rsipka): Deprecated operations on 'char' #28006, it should be removed from ETS_CONVERTIBLE_TO_NUMERIC + return (unboxed != nullptr) && unboxed->HasTypeFlag(TypeFlag::ETS_CONVERTIBLE_TO_NUMERIC) && + !unboxed->HasTypeFlag(TypeFlag::CHAR); } bool ETSChecker::CheckIfFloatingPoint(Type *type) @@ -489,7 +492,7 @@ checker::Type *ETSChecker::CheckBinaryOperatorShift( return isPrim ? GlobalLongType() : GetGlobalTypesHolder()->GlobalLongBuiltinType(); } - if (unboxedProm->IsByteType() || unboxedProm->IsShortType() || unboxedProm->IsCharType()) { + if (unboxedProm->IsByteType() || unboxedProm->IsShortType()) { return promotedLeftType; } @@ -539,7 +542,7 @@ checker::Type *ETSChecker::CheckBinaryOperatorBitwise( return isPrim ? GlobalLongType() : GetGlobalTypesHolder()->GlobalLongBuiltinType(); } - if (unboxedProm->IsByteType() || unboxedProm->IsShortType() || unboxedProm->IsCharType()) { + if (unboxedProm->IsByteType() || unboxedProm->IsShortType()) { return promotedType; } return nullptr; diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index dd5d023d62c7fecbc4b73fddc9445fff3850ba46..b4823f9371040711870d495f5c8e1f980ed2ea9b 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -405,15 +405,12 @@ Type *ETSChecker::GetUnaryOperatorPromotedType(Type *type, const bool doPromotio auto globalTypesHolder = GetGlobalTypesHolder(); if (doPromotion) { - // NOTE(dkofanov): Deprecated operations on 'char' #28006 if (type == globalTypesHolder->GlobalByteBuiltinType() || type == globalTypesHolder->GlobalShortBuiltinType() || - type == globalTypesHolder->GlobalCharBuiltinType() || type == globalTypesHolder->GlobalIntegerBuiltinType()) { return GlobalIntBuiltinType(); } - // NOTE(dkofanov): Deprecated operations on 'char' #28006 - if (type->IsIntType() || type->IsByteType() || type->IsShortType() || type->IsCharType()) { + if (type->IsIntType() || type->IsByteType() || type->IsShortType()) { return GlobalIntBuiltinType(); } } diff --git a/ets2panda/test/ast/compiler/ets/explicit_cast_boxed_expressions.ets b/ets2panda/test/ast/compiler/ets/explicit_cast_boxed_expressions.ets index 52fee19f867d7d415f954443a1d2ca41b962055b..2389bbc2343a0e0a2e8e0006202e0b054ff1b34d 100644 --- a/ets2panda/test/ast/compiler/ets/explicit_cast_boxed_expressions.ets +++ b/ets2panda/test/ast/compiler/ets/explicit_cast_boxed_expressions.ets @@ -19,7 +19,7 @@ let testInt: Int = new Int(42 as int); let testLong: Long = new Long(42 as long); let testFloat: Float = new Float(42 as float); let testDouble: Double = new Double(42 as double); -let testChar: Char = new Char(42 as char); +let testChar: Char = new Char(Int.toChar(42) as char); let testLongValue: Long = 9223372036854775807; function byte_test(): boolean { @@ -88,7 +88,7 @@ function short_test(): boolean { } function char_test(): boolean { - let Char_: Char = new Char(42 as char); + let Char_: Char = new Char(Int.toChar(42) as char); let char_byte = Char.toByte(Char_); let char_short = Char.toShort(Char_); diff --git a/ets2panda/test/ast/compiler/ets/implicit_cast_boxed_expressions.ets b/ets2panda/test/ast/compiler/ets/implicit_cast_boxed_expressions.ets index 8b80e53739954ff7e2383af62b1e82534493a0f3..949a32855c9b838da1ca32f7c2be84d6bc43da66 100644 --- a/ets2panda/test/ast/compiler/ets/implicit_cast_boxed_expressions.ets +++ b/ets2panda/test/ast/compiler/ets/implicit_cast_boxed_expressions.ets @@ -19,7 +19,7 @@ let testInt: Int = new Int(42 as int); let testLong: Long = new Long(42 as long); let testFloat: Float = new Float(42 as float); let testDouble: Double = new Double(42 as double); -let testChar: Char = new Char(42 as char); +let testChar: Char = new Char(Int.toChar(42)); let testLongValue: Long = 9223372036854775807; function byte_test(): boolean { @@ -30,7 +30,7 @@ function byte_test(): boolean { let byte_long = new Long(42 as long); let byte_float = new Float(42 as float); let byte_double = new Double(42 as double); - let byte_char = new Char(42 as char); + let byte_char = new Char(Int.toChar(42)); byte_byte = testByte; // Byte -> Byte byte_short = testByte; // Byte -> Short @@ -70,7 +70,7 @@ function short_test(): boolean { let short_long = new Long(42 as long); let short_float = new Float(42 as float); let short_double = new Double(42 as double); - let short_char = new Char(42 as char); + let short_char = new Char(Int.toChar(42)); // short_byte = testShort; // Short -> Byte is not available according 6.5.2 widening table and CTE happens short_short = testShort; // Short -> Short @@ -110,7 +110,7 @@ function char_test(): boolean { let char_long = new Long(42 as long); let char_float = new Float(42 as float); let char_double = new Double(42 as double); - let char_char = new Char(42 as char); + let char_char = new Char(Int.toChar(42)); // char_byte = testChar; // Char -> Byte is not available according 6.5.2 widening table and CTE happens // char_short = testChar; // Char -> Short is not available according 6.5.2 widening table and CTE happens @@ -157,7 +157,7 @@ function int_test(): boolean { let int_long = new Long(42 as long); let int_float = new Float(42 as float); let int_double = new Double(42 as double); - let int_char = new Char(42 as char); + let int_char = new Char(Int.toChar(42)); // int_byte = testInt; // Int -> Byte is not available according 6.5.2 widening table and CTE happens // int_short = testInt; // Int -> Short is not available according 6.5.2 widening table and CTE happens @@ -196,7 +196,7 @@ function long_test(): boolean { let long_long = new Long(42 as long); let long_float = new Float(42 as float); let long_double = new Double(42 as double); - let long_char = new Char(42 as char); + let long_char = new Char(Int.toChar(42)); // long_byte = testLong; // Long -> Byte is not available according 6.5.2 widening table and CTE happens // long_short = testLong; // Long -> Short is not available according 6.5.2 widening table and CTE happens @@ -235,7 +235,7 @@ function float_test(): boolean { let float_long = new Long(42 as long); let float_float = new Float(42 as float); let float_double = new Double(42 as double); - let float_char = new Char(42 as char); + let float_char = new Char(Int.toChar(42)); // float_byte = testFloat; // Float -> Byte is not available according 6.5.2 widening table and CTE happens // float_short = testFloat; // Float -> Short is not available according 6.5.2 widening table and CTE happens @@ -275,7 +275,7 @@ function double_test(): boolean { let double_long = new Long(42 as long); let double_float = new Float(42 as float); let double_double = new Double(42 as double); - let double_char = new Char(42 as char); + let double_char = new Char(Int.toChar(42) as char); // double_byte = testDouble; // Double -> Byte is not available according 6.5.2 widening table and CTE happens // double_short = testDouble; // Double -> Short is not available according 6.5.2 widening table and CTE happens diff --git a/ets2panda/test/ast/compiler/ets/shiftOperatorWithChar.ets b/ets2panda/test/ast/compiler/ets/shiftOperatorWithChar.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1484a2e33eddb5bfbb937cfd63f4b26db1e9867 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/shiftOperatorWithChar.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main(): void { + let result = c'a' >> 1 +} + +/* @@? 17:16 Error TypeError: Wrong type of operands for binary expression */ +/* @@? 17:16 Error TypeError: Bad operand type, the types of the operands must be numeric type. */