From 287a98fe5b0b75e754b6e55db303a07523b642c4 Mon Sep 17 00:00:00 2001 From: ignatenkooleg Date: Mon, 8 Sep 2025 21:22:21 +0300 Subject: [PATCH] 4.6.2 '?' is used after name of the constant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICWKAA Testing: all pre-merge tests passed, logs available in ggWatcher Signed-off-by: ignatenkooleg --- .../bad_const_decl_qmark.ets | 27 +++ .../bad_const_decl_qmark.params.yaml | 29 +++ .../const_decl_qmark.ets | 28 +++ .../const_decl_qmark.params.yaml | 93 ++++++++++ .../const_decl_qmark2.ets | 36 ++++ .../const_decl_qmark2.params.yaml | 171 ++++++++++++++++++ .../ets-cts/declgen-ets2ts-cts-ignored.txt | 5 + .../test-lists/ets-cts/ets-cts-ignored.txt | 31 ++++ 8 files changed, 420 insertions(+) create mode 100644 static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/bad_const_decl_qmark.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/bad_const_decl_qmark.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2.params.yaml diff --git a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/bad_const_decl_qmark.ets b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/bad_const_decl_qmark.ets new file mode 100644 index 0000000000..ac37c0c778 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/bad_const_decl_qmark.ets @@ -0,0 +1,27 @@ +/*--- +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: Incorrect constant definition +tags: [negative, compile-only] +---*/ + +{{c.decl}} + +function main(): void { + {{c.use}} +} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/bad_const_decl_qmark.params.yaml b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/bad_const_decl_qmark.params.yaml new file mode 100644 index 0000000000..f8361a7c8d --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/bad_const_decl_qmark.params.yaml @@ -0,0 +1,29 @@ +# 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. + +--- # List of incorrect const declaration forms when '?' is used after name of the constant +cases: + - { decl: 'const x?;' } + - { decl: 'const y?: int;' } + - { decl: 'const x? = 1, y?: int;' } + - { decl: 'const x? = 1; const x? = 2;' } + - { decl: 'let x = 1; const x? = 2;' } + - { decl: 'const x? = 1; let x = 2;' } + - { decl: 'const x? = 1; let y = 2; const x = 3;' } + - { decl: 'const x?: int = new Object();' } + - { decl: 'const x?: Object = null;' } + - { decl: 'const x?: Object|null' } + - { decl: 'let y = "yes"; const x?: boolean = y;' } + - { decl: 'const obj?: Object|null = new Object();', use: 'obj = null;' } + - { decl: 'let value: string | undefined = "string"; const obj?: int = value;' } + - { decl: 'let value: string | undefined = "string"; let obj?: int = value;' } diff --git a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark.ets b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark.ets new file mode 100644 index 0000000000..dcebef0287 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark.ets @@ -0,0 +1,28 @@ +/*--- +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: A constant declaration introduces a named entity with mandatory initial value +---*/ + +{{c.decl}} + +function main(): void { + {{c.use}} + arktest.assertTrue( {{c.assert}} ) +} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark.params.yaml b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark.params.yaml new file mode 100644 index 0000000000..cb530aeb74 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark.params.yaml @@ -0,0 +1,93 @@ +# 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: + - decl: 'const Const?: int = 1;' + assert: Const == 1 + + - decl: 'const b? = 1;' + assert: b == 1 + + - use: 'const c?: int = 6, d? = 1, e? = "hello";' + assert: c == 6 && d == 1 && e == "hello" + + - use: 'let a = 1; const b? = a; a = 2;' + assert: b == 1 + + - use: 'let a: int; const b? = a; a = 2;' + assert: b == 0 + + - decl: 'let a: Object|null = null' + use: const b? = a; + assert: b == null + + - decl: 'let a: Object|undefined' + use: const b? = a; + assert: b == undefined + + - use: 'let a: int = 42; const b?: long = a * 2;' + assert: b == 84 as long + + - decl: 'const x? = 42, y? = 2 * x, z? = 2 + y;' + assert: x == 42 && y == 84 && z == 86 + + - use: |- + const arr?: int[] = [1, 2, 3]; + arr[0] *= 2; + arr[1] += 2; + arr[2] /= 2; + assert: arr[0] == 2 && arr[1] == 4 && arr[2] == 1 + + - decl: |- + class A { + public fld: int; + } + use: 'const obj?: A = new A(); obj.fld = 42;' + assert: obj.fld == 42 + + - decl: |- + class A { + public fld: int; + } + use: 'const obj? = new A(); obj.fld = 42;' + assert: obj.fld == 42 + + - decl: |- + class A { + public fld: int; + } + use: 'const obj?: A = undefined;' + assert: obj instanceof undefined + + - decl: 'const Const?: int = undefined;' + assert: Const instanceof undefined + + - decl: 'const b? = undefined;' + assert: b instanceof undefined + + - use: 'const c?: int = undefined, d? = undefined, e? = undefined;' + assert: c instanceof undefined && d instanceof undefined && e instanceof undefined + + - use: 'let a = undefined; const b? = a;' + assert: b instanceof undefined + + - use: 'const a = undefined; const b? = a;' + assert: b instanceof undefined + + - use: 'const a? = undefined; const b? = a;' + assert: b instanceof undefined + + - use: |- + const arr?: int[] = undefined + assert: arr instanceof undefined diff --git a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2.ets b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2.ets new file mode 100644 index 0000000000..b09facf1a4 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2.ets @@ -0,0 +1,36 @@ +/*--- +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: A constant declaration introduces a named entity with mandatory initial value +---*/ + +type literal = "aa" +type tuple = [literal, int] +type tuple2 = [tuple, int] +type array = tuple[] +type fixed_array = FixedArray +type fooType = (p: literal) => literal +function foo(p: literal): literal { return p } + +{{c.decl}} + +function main(): void { + const some?{{c.type_annotation}} = {{c.initializer}} + arktest.assertTrue(some{{c.retrieve}} instanceof {{c.expected_type}} ) +} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2.params.yaml b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2.params.yaml new file mode 100644 index 0000000000..67f140ec49 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2.params.yaml @@ -0,0 +1,171 @@ +# 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. + +--- + +# specific types: literal, tuple, array, function, FixedArray, array[] etc. +# inferred and with type annotation, initialized with a value and with undefined +# initialized directly or via variable +cases: + # literal + - initializer: '"aa"' + expected_type: literal + + - type_annotation: ': literal' + initializer: '"aa"' + expected_type: literal + + - type_annotation: ': literal' + initializer: undefined + expected_type: undefined + + - decl: |- + let value: literal = "aa" + initializer: value + expected_type: literal + + - decl: |- + let value: literal = "aa" + type_annotation: ': literal' + initializer: value + expected_type: literal + + - decl: |- + let value: undefined = undefined + type_annotation: ': literal' + initializer: value + expected_type: undefined + + # tuple + - initializer: '["aa", 1]' + retrieve: '[0]' + expected_type: literal + + - type_annotation: ': tuple2' + initializer: '[["aa", 1], 1]' + retrieve: '[0][0]' + expected_type: literal + + - type_annotation: ': tuple2' + initializer: undefined + expected_type: undefined + + - decl: |- + let value: tuple2 = [["aa", 1], 1] + retrieve: '[0][0]' + initializer: value + expected_type: literal + + - decl: |- + let value: tuple2 = [["aa", 1], 1] + type_annotation: ': tuple2' + retrieve: '[0][0]' + initializer: value + expected_type: literal + + - decl: |- + let value: undefined = undefined + type_annotation: ': tuple2' + initializer: value + expected_type: undefined + + # function + - initializer: foo + expected_type: fooType + + - type_annotation: ': fooType' + initializer: foo + expected_type: fooType + + - type_annotation: ': fooType' + initializer: undefined + expected_type: undefined + + - decl: |- + let value: fooType = foo + initializer: value + expected_type: fooType + + - decl: |- + let value: fooType = foo + type_annotation: ': fooType' + initializer: value + expected_type: fooType + + - decl: |- + let value: undefined = undefined + type_annotation: ': fooType' + initializer: value + expected_type: undefined + + # FixedArray + - initializer: '[["aa", 1]]' + retrieve: '[0][0]' + expected_type: literal + + - type_annotation: ': fixed_array' + initializer: '[["aa", 1]]' + retrieve: '[0][0]' + expected_type: literal + + - type_annotation: ': fixed_array' + initializer: undefined + expected_type: undefined + + - decl: |- + let value: fixed_array = [["aa", 1]] + retrieve: '[0][0]' + initializer: value + expected_type: literal + + - decl: |- + let value: fixed_array = [["aa", 1]] + type_annotation: ': fixed_array' + retrieve: '[0][0]' + initializer: value + expected_type: literal + + - decl: |- + let value: undefined = undefined + type_annotation: ': fixed_array' + initializer: value + expected_type: undefined + + # array[] + - type_annotation: ': array' + initializer: '[["aa", 1]]' + retrieve: '[0][0]' + expected_type: literal + + - type_annotation: ': array' + initializer: undefined + expected_type: undefined + + - decl: |- + let value: array = [["aa", 1]] + retrieve: '[0][0]' + initializer: value + expected_type: literal + + - decl: |- + let value: array = [["aa", 1]] + type_annotation: ': array' + retrieve: '[0][0]' + initializer: value + expected_type: literal + + - decl: |- + let value: undefined = undefined + type_annotation: ': array' + initializer: value + expected_type: undefined diff --git a/static_core/plugins/ets/tests/test-lists/declgenets2ts/ets-cts/declgen-ets2ts-cts-ignored.txt b/static_core/plugins/ets/tests/test-lists/declgenets2ts/ets-cts/declgen-ets2ts-cts-ignored.txt index 5351568085..67093a8725 100644 --- a/static_core/plugins/ets/tests/test-lists/declgenets2ts/ets-cts/declgen-ets2ts-cts-ignored.txt +++ b/static_core/plugins/ets/tests/test-lists/declgenets2ts/ets-cts/declgen-ets2ts-cts-ignored.txt @@ -712,6 +712,11 @@ 04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/bad_const_decl_4.ets 04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/bad_const_decl_5.ets 04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/bad_const_decl_6.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/bad_const_decl_qmark_0.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/bad_const_decl_qmark_3.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/bad_const_decl_qmark_4.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/bad_const_decl_qmark_5.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/bad_const_decl_qmark_6.ets 04.names_declarations_and_scopes/06.variable_and_constant_declarations/04.type_inference_from_initializer/infer_n5.ets 04.names_declarations_and_scopes/07.function_declarations/02.parameter_list/param_list_neg_10.ets 04.names_declarations_and_scopes/07.function_declarations/02.parameter_list/param_list_neg_2.ets 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 af5ebc6342..f98d57dc0f 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 @@ -101,6 +101,37 @@ 04.names_declarations_and_scopes/04.accessible/type_name_const_enum.ets 04.names_declarations_and_scopes/04.accessible/type_name_variable_enum.ets +#29754 +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark_0.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark_2.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark_7.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark_9.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark_10.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark_12.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark_13.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark_15.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark_19.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_1.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_2.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_4.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_5.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_7.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_8.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_10.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_11.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_13.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_14.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_16.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_17.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_19.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_20.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_22.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_23.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_24.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_25.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_27.ets +04.names_declarations_and_scopes/06.variable_and_constant_declarations/02.constant_declarations/const_decl_qmark2_28.ets + #23643 04.names_declarations_and_scopes/06.variable_and_constant_declarations/04.type_inference_from_initializer/infer_12.ets 04.names_declarations_and_scopes/06.variable_and_constant_declarations/04.type_inference_from_initializer/infer_13.ets -- Gitee