From 847e8b7da8a693c08fb1a8f1d142fdc8c4fb2f13 Mon Sep 17 00:00:00 2001 From: Maksim Khramov Date: Tue, 2 Sep 2025 18:39:11 +0800 Subject: [PATCH] Extra CTS tests for 9.7.x chapters Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICWG7O Signed-off-by: Maksim Khramov Testing: All required pre-merge tests passed. Results are available in the GGW. --- .../10.break_statements/illegal_break_0.ets | 23 ++++++ .../10.break_statements/illegal_break_1.ets | 30 +++++++ ...thod_declaration_with_keywords.params.yaml | 3 +- ...tic_method_with_body_type_parameter_0.ets} | 13 ++- ...atic_method_with_body_type_parameter_1.ets | 29 +++++++ ...atic_method_with_body_type_parameter_2.ets | 29 +++++++ ...tract_method_declaration_with_block_0.ets} | 2 +- ...stract_method_declaration_with_block_1.ets | 26 ++++++ ...stract_method_declaration_with_block_2.ets | 27 ++++++ ...stract_method_declaration_with_block_3.ets | 26 ++++++ ...ract_method_declaration_with_semicolon.ets | 2 +- .../method_declaration_with_block.ets | 2 +- .../method_declaration_with_return_type.ets | 2 +- .../method_declaration_with_semicolon.ets | 2 +- .../method_without_return_statement.ets | 2 +- .../native_method_declaration_with_block.ets | 2 +- ...tive_method_declaration_with_semicolon.ets | 2 +- .../met_ret_this.params.yaml | 56 +++++++++++++ .../met_ret_this_n.params.yaml | 82 ++++++------------- .../RestOptionalLambdasInMethod_0.ets | 41 ++++++++++ .../TwoOptionalLambdasInMethod_0.ets | 36 ++++++++ .../TwoOptionalLambdasInMethod_1.ets | 37 +++++++++ .../TwoOptionalLambdasInMethod_2.ets | 37 +++++++++ ...method_declaration_with_existed_name_2.ets | 29 +++++++ ...method_declaration_with_existed_name_3.ets | 29 +++++++ .../method_modifier_duplicate_0.ets | 25 ++++++ .../method_modifier_duplicate_1.ets | 25 ++++++ .../method_modifier_duplicate_2.ets | 25 ++++++ .../method_modifier_duplicate_3.ets | 25 ++++++ .../method_modifier_duplicate_4.ets | 25 ++++++ .../method_modifier_duplicate_5.ets | 25 ++++++ .../method_modifier_duplicate_6.ets | 25 ++++++ .../test-lists/ets-cts/ets-cts-ignored.txt | 9 ++ 33 files changed, 679 insertions(+), 74 deletions(-) create mode 100644 static_core/plugins/ets/tests/ets-templates/08.statements/10.break_statements/illegal_break_0.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/08.statements/10.break_statements/illegal_break_1.ets rename static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/{static_method_with_body_type_parameter.ets => static_method_with_body_type_parameter_0.ets} (71%) create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_with_body_type_parameter_1.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_with_body_type_parameter_2.ets rename static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/{abstract_method_declaration_with_block.ets => abstract_method_declaration_with_block_0.ets} (94%) create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block_1.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block_2.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block_3.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/RestOptionalLambdasInMethod_0.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/TwoOptionalLambdasInMethod_0.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/TwoOptionalLambdasInMethod_1.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/TwoOptionalLambdasInMethod_2.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_declaration_with_existed_name_2.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_declaration_with_existed_name_3.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_0.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_1.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_2.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_3.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_4.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_5.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_6.ets diff --git a/static_core/plugins/ets/tests/ets-templates/08.statements/10.break_statements/illegal_break_0.ets b/static_core/plugins/ets/tests/ets-templates/08.statements/10.break_statements/illegal_break_0.ets new file mode 100644 index 0000000000..1b403ed1a2 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/08.statements/10.break_statements/illegal_break_0.ets @@ -0,0 +1,23 @@ +/*--- +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: Break statements. If a break statement is used outside a loopStatement or a switchStatement, then a compile-time error occurs. +tags: [negative, compile-only] +---*/ + +function main() { + break +} diff --git a/static_core/plugins/ets/tests/ets-templates/08.statements/10.break_statements/illegal_break_1.ets b/static_core/plugins/ets/tests/ets-templates/08.statements/10.break_statements/illegal_break_1.ets new file mode 100644 index 0000000000..06e864cea7 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/08.statements/10.break_statements/illegal_break_1.ets @@ -0,0 +1,30 @@ +/*--- +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: Break statements. If a break statement is used outside a loopStatement or a switchStatement, then a compile-time error occurs. +tags: [negative, compile-only] +---*/ + + +class ABreakIllegal { + foo() { + break + } +} + +function main() { + +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_declaration_with_keywords.params.yaml b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_declaration_with_keywords.params.yaml index c8f8d78b19..867833998b 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_declaration_with_keywords.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_declaration_with_keywords.params.yaml @@ -11,9 +11,10 @@ # See the License for the specific language governing permissions and # limitations under the License. ---- # List of valid method modifiers +--- # List of invalid static method modifiers modifiers: - "abstract" - "override" - "open" - "synchronized" + - 'final' diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_with_body_type_parameter.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_with_body_type_parameter_0.ets similarity index 71% rename from static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_with_body_type_parameter.ets rename to static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_with_body_type_parameter_0.ets index 88aec76142..058bcebb20 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_with_body_type_parameter.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_with_body_type_parameter_0.ets @@ -1,5 +1,5 @@ /*--- -Copyright (c) 2021-2025 Huawei Device Co., Ltd. +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 @@ -14,17 +14,14 @@ limitations under the License. ---*/ /*--- -desc: Static method declaration with parameter of type declared in body of method class. +desc: Static method declaration with parameter of type declared in body of the surrounding declaration. assert: >- - It is a compile-time error to use the name of a parameter of any surrounding declaration - in the header or body of a class. + The header or body of a class method includes the name of a type parameter of the surrounding declaration. tags: [compile-only, negative] ---*/ -class A { - inner class B { +class A { + static foo(b: CTE): void { } - - static foo(b: B): void; } diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_with_body_type_parameter_1.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_with_body_type_parameter_1.ets new file mode 100644 index 0000000000..84f9e26e8e --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_with_body_type_parameter_1.ets @@ -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. +---*/ + +/*--- +desc: Static method declaration with parameter of type declared in body of the surrounding declaration. +assert: >- + The header or body of a class method includes the name of a type parameter of the surrounding declaration. +tags: [compile-only, negative] +---*/ + +class A { + + static foo(): CTE | undefined { + return undefined + } + +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_with_body_type_parameter_2.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_with_body_type_parameter_2.ets new file mode 100644 index 0000000000..b201b7ce39 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/01.static_methods/static_method_with_body_type_parameter_2.ets @@ -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. +---*/ + +/*--- +desc: Static method declaration with parameter of type declared in body of the surrounding declaration. +assert: >- + The header or body of a class method includes the name of a type parameter of the surrounding declaration. +tags: [compile-only, negative] +---*/ + +class A { + + static foo(): void { + let pass: CTE | undefined = undefined + } + +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block_0.ets similarity index 94% rename from static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block.ets rename to static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block_0.ets index de0d850c30..38e9e1bb2c 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block_0.ets @@ -14,7 +14,7 @@ */ /*--- -desc: Abstract method declaraion with block of code. +desc: Abstract method declaration with block of code. assert: It is a compile-time error if a method declaration is either abstract or native and has a block for its body. tags: [compile-only, negative] ---*/ diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block_1.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block_1.ets new file mode 100644 index 0000000000..6cb06d5adf --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block_1.ets @@ -0,0 +1,26 @@ +/* + * 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: Abstract method declaration with block of code. +assert: It is a compile-time error if a method declaration is either abstract or native and has a block for its body. +tags: [compile-only, negative] +---*/ + +abstract class A { + abstract run(): void { + return + } +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block_2.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block_2.ets new file mode 100644 index 0000000000..c2b89c620d --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block_2.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. + */ + +/*--- +desc: Abstract method declaration with block of code. +assert: It is a compile-time error if a method declaration is either abstract or native and has a block for its body. +tags: [compile-only, negative] +---*/ + +abstract class A { + abstract run(): void { + { + } + } +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block_3.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block_3.ets new file mode 100644 index 0000000000..a7e6307855 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_block_3.ets @@ -0,0 +1,26 @@ +/* + * 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: Abstract method declaration with block of code. +assert: It is a compile-time error if a method declaration is either abstract or native and has a block for its body. +tags: [compile-only, negative] +---*/ + +abstract class A { + abstract run(): void { + ; + } +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_semicolon.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_semicolon.ets index 3de38cb334..7a170b8835 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_semicolon.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/abstract_method_declaration_with_semicolon.ets @@ -14,7 +14,7 @@ */ /*--- -desc: Abstract method declaraion with simply semicolon. +desc: Abstract method declaration with simply semicolon. assert: The body of a method must be a semicolon if the method is abstract or native. tags: [compile-only] ---*/ diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/method_declaration_with_block.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/method_declaration_with_block.ets index af815396c7..9832b32d7e 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/method_declaration_with_block.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/method_declaration_with_block.ets @@ -14,7 +14,7 @@ */ /*--- -desc: Method declaraion with block of code. +desc: Method declaration with block of code. assert: >- A method body is either a block of code that implements the method or simply a semicolon, indicating the lack of an implementation. diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/method_declaration_with_return_type.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/method_declaration_with_return_type.ets index 6465465b13..c44028dabf 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/method_declaration_with_return_type.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/method_declaration_with_return_type.ets @@ -14,7 +14,7 @@ */ /*--- -desc: Method declaraion with return type. +desc: Method declaration with return type. assert: >- If a method is declared to have a return type, then a compile-time error occurs if the body of the method can complete normally. diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/method_declaration_with_semicolon.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/method_declaration_with_semicolon.ets index 105442acc5..d6daf292c8 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/method_declaration_with_semicolon.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/method_declaration_with_semicolon.ets @@ -14,7 +14,7 @@ */ /*--- -desc: Method declaraion with simply semicolon. +desc: Method declaration with simply semicolon. assert: >- A method body is either a block of code that implements the method or simply a semicolon, indicating the lack of an implementation. It is a compile-time error if a method declaration is neither abstract diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/method_without_return_statement.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/method_without_return_statement.ets index 662d3fa668..39e2767f90 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/method_without_return_statement.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/method_without_return_statement.ets @@ -14,7 +14,7 @@ */ /*--- -desc: Method declaraion with return type. +desc: Method declaration with return type. assert: >- If a method is declared to have a return type, then a compile-time error occurs if the body of the method can complete normally. diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/native_method_declaration_with_block.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/native_method_declaration_with_block.ets index 840132ddd6..0d5714acda 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/native_method_declaration_with_block.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/native_method_declaration_with_block.ets @@ -14,7 +14,7 @@ */ /*--- -desc: Native method declaraion with block of code. +desc: Native method declaration with block of code. assert: It is a compile-time error if a method declaration is either abstract or native and has a block for its body. tags: [compile-only, negative] ---*/ diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/native_method_declaration_with_semicolon.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/native_method_declaration_with_semicolon.ets index a3294b4cc4..f4c17b567a 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/native_method_declaration_with_semicolon.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/07.method_body/native_method_declaration_with_semicolon.ets @@ -14,7 +14,7 @@ */ /*--- -desc: Native method declaraion with simply semicolon. +desc: Native method declaration with simply semicolon. assert: The body of a method must be a semicolon if the method is abstract or native. tags: [compile-only] ---*/ diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/08.methods_returning_this/met_ret_this.params.yaml b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/08.methods_returning_this/met_ret_this.params.yaml index b0fdc190da..4b82e91e5a 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/08.methods_returning_this/met_ret_this.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/08.methods_returning_this/met_ret_this.params.yaml @@ -583,3 +583,59 @@ cases: let a = new A arktest.assertEQ((await (await a.foo()).foo()), a) arktest.assertEQ(a.fld, 2) + + - decl: |- + class A { + fld: int + foo(): this { + if (this.fld == 0) { + return this.bar() + } + throw new Error + } + bar(): this { + if (this.fld == 0) { + return this + } + throw new Error + } + } + use: |- + let x = new A().foo() + + - decl: |- + class A { + fld: int + foo(): this { + return this.fld == 0 ? this : this.bar() + } + bar(): this { + if (this.fld == 0) { + return this + } + throw new Error + } + } + use: |- + let x = new A().foo() + + - decl: |- + abstract class Super { + fld: int + foo(): this { + if (this.fld == 0) { + return this + } + throw new Error + } + } + class A extends Super { + foo(): this { + if (this.fld == 999) { + return this + } + return super.foo() + } + } + use: |- + let x = new A().foo() diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/08.methods_returning_this/met_ret_this_n.params.yaml b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/08.methods_returning_this/met_ret_this_n.params.yaml index c1488a3b1b..3597a8dd13 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/08.methods_returning_this/met_ret_this_n.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/08.methods_returning_this/met_ret_this_n.params.yaml @@ -13,8 +13,9 @@ --- cases: + # case 0 - decl: |- - f: int + let f: int class A { static foo(): this { // CTE, 'this' cannot be used as return type of static method if (f == 0) { @@ -26,6 +27,7 @@ cases: use: |- let x = A.foo() + # case 1 - decl: |- class A { fld: int @@ -39,6 +41,7 @@ cases: use: |- let x = new A().foo() + # case 2 - decl: |- class A { fld: int @@ -52,6 +55,7 @@ cases: use: |- let x = new A().foo() + # case 3 - decl: |- class A { fld: int @@ -65,6 +69,7 @@ cases: use: |- let x = new A().foo() + # case 4 - decl: |- class A { fld: int @@ -78,62 +83,7 @@ cases: use: |- let x = new A().foo() - - decl: |- - class A { - fld: int - foo(): this { - if (this.fld == 0) { - return this.bar() // CTE, only 'this' is allowed in return - } - throw new Error - } - bar(): this { - if (this.fld == 0) { - return this - } - throw new Error - } - } - use: |- - let x = new A().foo() - - - decl: |- - class A { - fld: int - foo(): this { - return this.fld == 0 ? this : this.bar() // CTE, only 'this' is allowed in return - } - bar(): this { - if (this.fld == 0) { - return this - } - throw new Error - } - } - use: |- - let x = new A().foo() - - - decl: |- - abstract class Super { - fld: int - foo(): this { - if (this.fld == 0) { - return this - } - throw new Error - } - } - class A extends Super { - foo(): this { - if (this.fld == 999) { - return this - } - return super.foo() // CTE, only 'this' is allowed in return - } - } - use: |- - let x = new A().foo() - + # case 5 - decl: |- abstract class Super { fld: int @@ -155,6 +105,7 @@ cases: use: |- let x = new A().foo() + # case 6 - decl: |- abstract class Super { fld: int @@ -176,6 +127,7 @@ cases: use: |- let x = new A().foo() + # case 7 - decl: |- class A { fld: A @@ -189,6 +141,7 @@ cases: use: |- let x = new A().foo() + # case 8 - decl: |- class A { fld: int @@ -201,3 +154,18 @@ cases: } use: |- let x = new A().instance + + # case 9 + - decl: |- + final class A { + fld: int + foo(): this { // CTE + if (this.fld == 0) { + const tmp = this + return tmp + } + throw new Error + } + } + use: |- + let x = new A().instance diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/RestOptionalLambdasInMethod_0.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/RestOptionalLambdasInMethod_0.ets new file mode 100644 index 0000000000..07c97f86c2 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/RestOptionalLambdasInMethod_0.ets @@ -0,0 +1,41 @@ +/* + * 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: Conditional expression compile bug + + ---*/ + +type TL = (() => void) | undefined + +class RestOptionalLambdasInMethod { + + static foo(k1: string, k2: string, k3: string, ...lambdas: TL[]): boolean { + return lambdas[1] == undefined + } + foo(k1: string, k2: string, k3: string, ...lambdas: TL[]): boolean { + return lambdas[1] == undefined + } +} + +type TA = RestOptionalLambdasInMethod + +function main(): void { + let flag: boolean | undefined + let test: TA = new TA + arktest.assertTrue(test.foo('', '', '', ((): boolean | undefined => flag)() ? undefined : () => {}, undefined, undefined, () => {})) + arktest.assertTrue(TA.foo('', '', '', ((): boolean | undefined => flag)() ? undefined : () => {}, undefined, undefined, () => {})) +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/TwoOptionalLambdasInMethod_0.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/TwoOptionalLambdasInMethod_0.ets new file mode 100644 index 0000000000..6e4e7beb7b --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/TwoOptionalLambdasInMethod_0.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. + */ + + + /*--- + desc: Conditional expression compile bug + + ---*/ + +type TL = () => void + +class TwoOptionalLambdasInMethod { + + foo(k1: string, k2: string, k3: string, lambdaOne?: TL, lambdaTwo?: TL): boolean { + return lambdaTwo == undefined + } +} + +function main(): void { + let flag: boolean | undefined + const test: TwoOptionalLambdasInMethod = new TwoOptionalLambdasInMethod(); + + arktest.assertTrue(test.foo('', '', '', flag ? undefined : () => {}, undefined)) +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/TwoOptionalLambdasInMethod_1.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/TwoOptionalLambdasInMethod_1.ets new file mode 100644 index 0000000000..ba427708e3 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/TwoOptionalLambdasInMethod_1.ets @@ -0,0 +1,37 @@ +/* + * 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: Conditional expression compile bug + + ---*/ + +type TL = () => void + +class TwoOptionalLambdasInMethod { + + static foo(k1: string, k2: string, k3: string, lambdaOne?: TL, lambdaTwo?: TL): boolean { + return lambdaTwo == undefined + } +} + +type TA = TwoOptionalLambdasInMethod + +function main(): void { + let flag: boolean | undefined + + arktest.assertTrue(TA.foo('', '', '', flag ? undefined : () => {}, undefined)) +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/TwoOptionalLambdasInMethod_2.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/TwoOptionalLambdasInMethod_2.ets new file mode 100644 index 0000000000..6590057d34 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/TwoOptionalLambdasInMethod_2.ets @@ -0,0 +1,37 @@ +/* + * 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: Conditional expression compile bug + + ---*/ + +type TL = () => void + +class TwoOptionalLambdasInMethod { + + static foo(k1: string, k2: string, k3: string, lambdaOne?: TL, lambdaTwo?: TL): boolean { + return lambdaTwo == undefined + } +} + +type TA = TwoOptionalLambdasInMethod + +function main(): void { + let flag: boolean | undefined + + arktest.assertTrue(TA.foo('', '', '', ((): boolean | undefined => flag)() ? undefined : () => {}, undefined)) +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_declaration_with_existed_name_2.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_declaration_with_existed_name_2.ets new file mode 100644 index 0000000000..30743e367e --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_declaration_with_existed_name_2.ets @@ -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. +---*/ + +/*--- +desc: Method declaration with existed name in class body declaration. +assert: >- + It is a compile-time error for the body of a class declaration to declare a method with the name + that is already used for field or a member type in this declaration. +tags: [compile-only, negative] +---*/ + +class Base { + private run: int; +} +final class Derive extends Base { + public run(): void {} +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_declaration_with_existed_name_3.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_declaration_with_existed_name_3.ets new file mode 100644 index 0000000000..c6211334e4 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_declaration_with_existed_name_3.ets @@ -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. +---*/ + +/*--- +desc: Method declaration with existed name in class body declaration. +assert: >- + It is a compile-time error for the body of a class declaration to declare a method with the name + that is already used for field or a member type in this declaration. +tags: [compile-only, negative] +---*/ + +class Base { + private static run: int; +} +final class Derive extends Base { + public static run(): void {} +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_0.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_0.ets new file mode 100644 index 0000000000..8341bebaee --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_0.ets @@ -0,0 +1,25 @@ +/* + * 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: Method declaration with duplicated modifier + + tags: [compile-only, negative] + ---*/ + + +abstract class A { + abstract abstract run(): void; +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_1.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_1.ets new file mode 100644 index 0000000000..ab0b7e011c --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_1.ets @@ -0,0 +1,25 @@ +/* + * 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: Method declaration with duplicated modifier + + tags: [compile-only, negative] + ---*/ + + +final class A { + private private run(): void {} +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_2.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_2.ets new file mode 100644 index 0000000000..35d46dd7b2 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_2.ets @@ -0,0 +1,25 @@ +/* + * 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: Method declaration with duplicated modifier + + tags: [compile-only, negative] + ---*/ + + +final class A { + static static run(): void {} +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_3.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_3.ets new file mode 100644 index 0000000000..53fd97c945 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_3.ets @@ -0,0 +1,25 @@ +/* + * 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: Method declaration with duplicated modifier + + tags: [compile-only, negative] + ---*/ + + +final class A { + native native run(): void; +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_4.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_4.ets new file mode 100644 index 0000000000..30e352620d --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_4.ets @@ -0,0 +1,25 @@ +/* + * 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: Method declaration with duplicated modifier + + tags: [compile-only, negative] + ---*/ + + +final class A { + native static native run(): void; +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_5.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_5.ets new file mode 100644 index 0000000000..b783630ca8 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_5.ets @@ -0,0 +1,25 @@ +/* + * 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: Method declaration with duplicated modifier + + tags: [compile-only, negative] + ---*/ + + +class A { + final final run(): void {} +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_6.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_6.ets new file mode 100644 index 0000000000..5e30fa3281 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/07.method_declarations/method_modifier_duplicate_6.ets @@ -0,0 +1,25 @@ +/* + * 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: Method declaration with duplicated modifier + + tags: [compile-only, negative] + ---*/ + + +class A { + async async run(): Promise {} +} 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 beca84746e..83bf19fd98 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 @@ -1475,9 +1475,18 @@ # 26983 09.classes/06.field_declarations/06.overriding_fields/sample.ets +#29602 +09.classes/07.method_declarations/01.static_methods/static_method_with_body_type_parameter_0.ets +09.classes/07.method_declarations/01.static_methods/static_method_with_body_type_parameter_1.ets + #23238 Method returning 'this' returns wrong instance 09.classes/07.method_declarations/08.methods_returning_this/met_ret_this_8.ets +#29600 +09.classes/07.method_declarations/08.methods_returning_this/met_ret_this_26.ets +09.classes/07.method_declarations/08.methods_returning_this/met_ret_this_27.ets +09.classes/07.method_declarations/08.methods_returning_this/met_ret_this_28.ets + #26730 09.classes/09.constructor_declaration/constructor_declaration_overload1.ets 09.classes/09.constructor_declaration/constructor_declaration_overload2.ets -- Gitee