diff --git a/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/negative_binary_operator_cts.ets b/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/negative_binary_operator_cts.ets new file mode 100644 index 0000000000000000000000000000000000000000..5421669ad2acbb2bb5d498790c2cc60f3da5ed5f --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/negative_binary_operator_cts.ets @@ -0,0 +1,34 @@ +/* + * 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. + */ + +{%- for c in cases %} +/*--- +desc: For other numeric operators, the operands of unary and binary numeric expressions are widened to a larger numeric + type. The minimum type is int. None of those operators evaluates values of types byte and short without + widening. +tags: [compile-only, negative] +---*/ + +function foo(x: short) { +} + +function main() { + let b: byte = 1 + let s: short = 2 + let x = b {{c}} s + + foo(x); // Should be CTE: TypeError: No matching call signature for foo(Int) +} +{%- endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/negative_binary_operator_cts.params.yaml b/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/negative_binary_operator_cts.params.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ee9e4f8b9909760fc683866130a3ae31539f6f11 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/negative_binary_operator_cts.params.yaml @@ -0,0 +1,20 @@ +# 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. + +--- +cases: + - '+' + - '-' + - '*' + - '/' + - '%' \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/negative_unary_operator.ets b/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/negative_unary_operator_cts.ets similarity index 65% rename from static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/negative_unary_operator.ets rename to static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/negative_unary_operator_cts.ets index 1c04c8fd0e521c1e31d3276c703614a7465be0e8..a548df7ea6c22e91027e5490c64fbe92f7620343 100644 --- a/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/negative_unary_operator.ets +++ b/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/negative_unary_operator_cts.ets @@ -13,9 +13,11 @@ * limitations under the License. */ - +{%- for c in cases %} /*--- -desc: Specifically, no arithmetic operator evaluates values of types byte and short without widening. +desc: For other numeric operators, the operands of unary and binary numeric expressions are widened to a larger numeric + type. The minimum type is int. None of those operators evaluates values of types byte and short without + widening. tags: [compile-only, negative] ---*/ @@ -24,5 +26,8 @@ function foo(x: short) { function main() { let b: byte = 1 - foo(b++) // #27628: Should be CTE: TypeError: No matching call signature for foo(Int) + let x = {{c}}b + + foo(x); // Should be CTE: TypeError: No matching call signature for foo(Int) } +{%- endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/negative_unary_operator_cts.params.yaml b/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/negative_unary_operator_cts.params.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7dea5403ca3ecc841456ca233cb06d6915db5ea6 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/negative_unary_operator_cts.params.yaml @@ -0,0 +1,18 @@ +# 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. + +--- +cases: + - '~' + - '-' + - '+' \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/numeric_expressions_no_widening.ets b/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/numeric_expressions_no_widening.ets new file mode 100644 index 0000000000000000000000000000000000000000..ebf2f1385f3a1df9feadf842605bf56367166e50 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/numeric_expressions_no_widening.ets @@ -0,0 +1,35 @@ +/* + * 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. + */ + +/*--- +desc: >- + The postfix and prefix increment and decrement operators evaluate byte and short operands without + widening. Same is true also for an assignment operator (considering assignment as a binary operator). +---*/ + +function main() { +{%- for t in type %} + let y_{{t}}: {{t}} = 1 + +{%- for op in unaryop %} + let x_{{t}}_prefix_{{loop.index}} = {{op}}y_{{t}} + arktest.assertTrue(x_{{t}}_prefix_{{loop.index}} instanceof {{t}}) + let x_{{t}}_postfix_{{loop.index}} = y_{{t}}{{op}} + arktest.assertTrue(x_{{t}}_postfix_{{loop.index}} instanceof {{t}}) +{%- endfor %} + let x_{{t}}_assignment = y_{{t}} + arktest.assertTrue(x_{{t}}_assignment instanceof {{t}}) +{%- endfor %} +} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/numeric_expressions_no_widening.params.yaml b/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/numeric_expressions_no_widening.params.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9aaf57ffe75cb746bd999424795f0cab9955f9ee --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/numeric_expressions_no_widening.params.yaml @@ -0,0 +1,24 @@ +# 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. + +type: + - byte + - short + - int + - long +unaryop: + - '++' + - '--' +position: + - 'prefix' + - 'postfix' \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/numeric_expressions_widening.ets b/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/numeric_expressions_widening.ets index 74a1899f2950e610812e25bc95113eadde650209..439bc1592b80a4bb203140626b9eb85e1b4a8384 100644 --- a/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/numeric_expressions_widening.ets +++ b/static_core/plugins/ets/tests/ets-templates/15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/numeric_expressions_widening.ets @@ -21,9 +21,9 @@ desc: >- function main() { let b: byte = 1 - let s: short = 2 + let s: Short = 2 let i: int = 3 - let l: long = 4 + let l: Long = 4 {%- for c in binary %} let x1_{{loop.index}} = b {{c}} b @@ -43,5 +43,9 @@ function main() { arktest.assertTrue(y1_{{loop.index}} instanceof int) let y2_{{loop.index}} = {{c}}s arktest.assertTrue(y2_{{loop.index}} instanceof int) + let y3_{{loop.index}} = {{c}}i + arktest.assertTrue(y3_{{loop.index}} instanceof int) + let y4_{{loop.index}} = {{c}}l + arktest.assertTrue(y4_{{loop.index}} instanceof long) {%- endfor -%} -} +} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/test-lists/ets-cts/ets-cts-ignored.txt b/static_core/plugins/ets/tests/test-lists/ets-cts/ets-cts-ignored.txt index beca84746e07de7217fe65b57031f9a26c4a92d8..f6077fe3bedbe8c648adfe6d4bca7a8c98f06992 100644 --- a/static_core/plugins/ets/tests/test-lists/ets-cts/ets-cts-ignored.txt +++ b/static_core/plugins/ets/tests/test-lists/ets-cts/ets-cts-ignored.txt @@ -2743,9 +2743,6 @@ # 27390 15.semantic_rules/01.semantic_essentials/01.type_of_standalone_expression/union_types.ets -# 27628 -15.semantic_rules/01.semantic_essentials/04.specifics_of_numeric_operator_contexts/negative_unary_operator.ets - # 28436 15.semantic_rules/08.overriding/01.overriding_in_classes/access_modifier_over_private_5.ets 15.semantic_rules/08.overriding/01.overriding_in_classes/access_modifier_over_private_6.ets