From 38f1595ed44e659dff45096d19b5498b37993fd1 Mon Sep 17 00:00:00 2001 From: Maksim Khramov Date: Mon, 8 Sep 2025 16:59:02 +0800 Subject: [PATCH] CTS tests for 7.14 and 7.30 Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICX79L Signed-off-by: Maksim Khramov Testing: All required pre-merge tests passed. Results are available in the GGW. --- .../14.new_expressions/AliasAsType_0.ets | 29 +++++++++ .../14.new_expressions/AliasAsType_1.ets | 29 +++++++++ .../NewExpressionExceptional.sts | 40 +++++++++++++ .../14.new_expressions/RefAsType_0.ets | 26 ++++++++ .../14.new_expressions/RefAsType_1.ets | 26 ++++++++ .../class_instance_creation_expressions.ets | 10 +++- ..._instance_creation_expressions.params.yaml | 50 +++++++++++++++- .../MenuOrEmpty.ets | 50 ++++++++++++++++ .../assign_conditional_void.ets | 37 ++++++++++++ .../assign_conditional_void_or_object.ets | 36 +++++++++++ .../conditional_expression_object_0.ets | 12 ++-- .../conditional_expression_object_2.ets | 4 +- .../conditional_expression_object_4.ets | 5 +- .../conditional_expression_object_6.ets | 5 +- .../conditional_expression_object_7.ets | 5 +- .../conditional_expression_object_9.ets | 45 ++++++++++++++ .../conditional_expression_order.ets | 4 +- .../conditional_expression_order_0.ets | 59 +++++++++++++++++++ ...constructor_declaration_no_parenthesis.sts | 25 ++++++++ .../constructor_declaration_with_field.sts | 25 ++++++++ .../test-lists/ets-cts/ets-cts-ignored.txt | 3 + 21 files changed, 510 insertions(+), 15 deletions(-) create mode 100644 static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/AliasAsType_0.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/AliasAsType_1.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/NewExpressionExceptional.sts create mode 100644 static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/RefAsType_0.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/RefAsType_1.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/MenuOrEmpty.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/assign_conditional_void.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/assign_conditional_void_or_object.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_9.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_order_0.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/09.constructor_declaration/constructor_declaration_no_parenthesis.sts create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/09.constructor_declaration/constructor_declaration_with_field.sts diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/AliasAsType_0.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/AliasAsType_0.ets new file mode 100644 index 0000000000..eaf2fd17d1 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/AliasAsType_0.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: Type reference is a type alias +tags: [] +---*/ + +class Testee { +} + +type Alias = String + +function main(): void { + new Testee() + new Testee +} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/AliasAsType_1.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/AliasAsType_1.ets new file mode 100644 index 0000000000..4df9e82e6b --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/AliasAsType_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: Type reference is a type alias +tags: [] +---*/ + +class Testee { +} + +type Alias = String + +function main(): void { + new Testee() + new Testee +} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/NewExpressionExceptional.sts b/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/NewExpressionExceptional.sts new file mode 100644 index 0000000000..3610aa9e75 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/NewExpressionExceptional.sts @@ -0,0 +1,40 @@ +/*--- +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: Class instance creation expression can throw an error +tags: [] +---*/ + +class IAmBad { + constructor () { + throw new Error() + } +} + +function main(): void { + let cc: int = 0; + try { + new IAmBad + } catch(e) { + cc++ + } + try { + new IAmBad() + } catch(e) { + cc++ + } + arktest.assertEQ(2, cc) +} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/RefAsType_0.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/RefAsType_0.ets new file mode 100644 index 0000000000..cfc48360bc --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/RefAsType_0.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: A compile-time error occurs if typeReference is a type parameter. +tags: [compile-only, negative] +---*/ + +class Testee { +} + +function main(): void { + new Testee() +} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/RefAsType_1.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/RefAsType_1.ets new file mode 100644 index 0000000000..14288be627 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/RefAsType_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: A compile-time error occurs if typeReference is a type parameter. +tags: [compile-only, negative] +---*/ + +class Testee { +} + +function main(): void { + new Testee() +} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/class_instance_creation_expressions.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/class_instance_creation_expressions.ets index 795c9dab63..6ef64a32e7 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/class_instance_creation_expressions.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/class_instance_creation_expressions.ets @@ -17,12 +17,16 @@ limitations under the License. /*--- desc: Class instance creation expression -params: {{ins.init}} + ---*/ -{{ins.decl}} +class Testee { + {{ins.decl}} +} + +type A = Testee -function main(): void { +function main() { let x = {{ins.init}}; } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/class_instance_creation_expressions.params.yaml b/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/class_instance_creation_expressions.params.yaml index a9acf99d62..e15a26f55a 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/class_instance_creation_expressions.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/14.new_expressions/class_instance_creation_expressions.params.yaml @@ -13,5 +13,51 @@ --- # List of valid class instance creation samples class_instance: - - {decl: "class A{}", init: "new A"} - - {decl: "", init: "new String"} + - decl: '' + init: 'new Testee' + + - decl: 'constructor () {}' + init: 'new Testee' + + - decl: 'constructor () {}' + init: 'new A' + + - decl: |- + constructor () {} + callme(): this { return this } + init: 'new A().callme()' + + - decl: |- + constructor () {} + callme(): this { return this } + init: '(new A).callme()' + + - decl: 'constructor () {}' + init: '(() => { return new A })()' + + - decl: 'constructor () {}' + init: '(() => { return [new A(), new Testee][0] })()' + + - decl: 'constructor (input?: String) {}' + init: 'new Testee' + + - decl: "constructor (input: String = 'Hello World') {}" + init: 'new Testee' + + - decl: 'constructor (...input: String[]) {}' + init: 'new Testee' + + - decl: 'constructor (...input: String[]) {}' + init: 'new A' + + - decl: 'constructor (...input: A[]) {}' + init: 'new Testee(new A, new A, new A)' + + - decl: '' + init: 'new String' + + - decl: '' + init: 'new number[2][2]' + + - decl: '' + init: 'new A[2][2]' diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/MenuOrEmpty.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/MenuOrEmpty.ets new file mode 100644 index 0000000000..56b7c59e6f --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/MenuOrEmpty.ets @@ -0,0 +1,50 @@ +/* + * 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: Type of the conditional expression is determined as the union of types of the second and the third expressions +tags: [] +---*/ + +final class Menu {} + +final class MenuProvider { + menuList?: Array +} + +final class View { + menu: Array; + constructor(mp: MenuProvider) { + this.menu = mp.menuList == undefined ? [] : mp.menuList! + } +} + +function build(isEmpty: boolean = true): MenuProvider { + let mp = new MenuProvider + if(isEmpty) return mp + + let am = [new Menu, new Menu] + mp.menuList = am; + return mp; + +} + +function main() { + let view: View = new View(build()) + arktest.assertEQ(0, view.menu.length) + + view = new View(build(false)) + arktest.assertEQ(2, view.menu.length) +} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/assign_conditional_void.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/assign_conditional_void.ets new file mode 100644 index 0000000000..b7b8cc34a2 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/assign_conditional_void.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: Type of the conditional expression is determined as the union of types of the second and the third expressions +tags: [compile-only, negative] +---*/ + + +function foo(): void { +} + +final class C { + static foo(): void { + + } +} + +type BRF = (input: boolean ) => boolean +const bo: BRF = (input: boolean) => { return input } + +function main(): void { + let x = bo(true) ? foo() : C.foo() + +} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/assign_conditional_void_or_object.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/assign_conditional_void_or_object.ets new file mode 100644 index 0000000000..cb1f082ca8 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/assign_conditional_void_or_object.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: Type of the conditional expression is determined as the union of types of the second and the third expressions +tags: [compile-only, negative] +---*/ + + +function foo(): void { +} + +final class C { + static foo(): String { + return 'Hello World' + } +} + +type BRF = (input: boolean ) => boolean +const bo: BRF = (input: boolean) => { return input } + +function main(): void { + let x = bo(true) ? foo() : C.foo() +} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_0.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_0.ets index d535a2285c..2d87c32c06 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_0.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_0.ets @@ -17,13 +17,17 @@ desc: Second operand is value type and third operand are reference type ---*/ -class A {} -class B {} +final class A {} +final class B {} + +type BRF = (input: boolean) => boolean function main(): void { + + const bf: BRF = (input: boolean) => { return input } + let a: int = 5; - let b: B = new B(); - let x = true ? a : b; + let x = bf(true) ? a : new B; arktest.assertTrue(x instanceof Int|B) } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_2.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_2.ets index 21f317967e..96d02ef4ac 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_2.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_2.ets @@ -20,11 +20,13 @@ desc: Second and third operands are of type parent/child Object types, bound to class A {} class B extends A {} +type BRF = (input: boolean ) => boolean +const bo: BRF = (input: boolean) => { return input } function main(): void { let a: A = new A(); let b: B = new B(); - let x = false ? a : b; + let x = bo(false) ? a : b; arktest.assertTrue( x instanceof A ) } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_4.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_4.ets index ee6f64d3fe..9a5c783272 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_4.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_4.ets @@ -21,10 +21,13 @@ class A {} class B extends A {} class D extends B {} +type BRF = (input: boolean ) => boolean +const bo: BRF = (input: boolean) => { return input } + function main(): void { let a: A = new A(); let d: D = new D(); - let x = false ? a : d; + let x = bo(false) ? a : d; arktest.assertTrue( x instanceof A ) } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_6.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_6.ets index a690c5b284..f9d3a5e7ec 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_6.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_6.ets @@ -23,9 +23,12 @@ function foo(p: A): int { return 2; } +type BRF = (input: boolean ) => boolean +const bo: BRF = (input: boolean) => { return input } + function main(): void { let a : A = new A(); let b : A = new A(); - let c = true ? a : b; + let c = bo(true) ? a : b; arktest.assertTrue(foo(c) == 2); } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_7.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_7.ets index 1bf5acb9de..e1654e5206 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_7.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_7.ets @@ -23,9 +23,12 @@ function foo(p: Object): int { return 1; } +type BRF = (input: boolean ) => boolean +const bo: BRF = (input: boolean) => { return input } + function main(): void { let a : A = new A(); let b : Int = 2; - let c = true ? a : b; + let c = bo(true) ? a : b; arktest.assertTrue(foo(c) == 1); } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_9.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_9.ets new file mode 100644 index 0000000000..95ad484bd3 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_object_9.ets @@ -0,0 +1,45 @@ +/* + * 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: Type of the conditional expression is determined as the union of types of the second and the third expressions +---*/ + +interface IEcho { + echo(): String { + return 'Hello World' + } +} +final class A implements IEcho {} +final class B implements IEcho {} + +final class C { + static echo(): IEcho { + return new B + } +} + +type BRF = (input: boolean ) => boolean +const bo: BRF = (input: boolean) => { return input } + +function main(): void { + + let bf: BRF = (input: boolean) => { return input } + + + let x = bf(true) ? new A : bo(false) ? C.echo() : new B; + arktest.assertTrue(x instanceof IEcho) + arktest.assertEQ('Hello World', x.echo()) +} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_order.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_order.ets index f5bcfa96ef..9e457b83e5 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_order.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_order.ets @@ -19,7 +19,7 @@ desc: Conditional expression order function main(): void { let cond = false; - let a = cond?1:cond?2:cond?3:0; - let b = cond?1:(cond?2:(cond?3:0)); + let a = cond ? 1 : cond ? 2 : cond ? 3 : 0; + let b = cond ? 1 : (cond ? 2 : (cond ? 3 : 0)); arktest.assertTrue( a == b ) } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_order_0.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_order_0.ets new file mode 100644 index 0000000000..af5bf8779f --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/30.conditional_expressions/conditional_expression_order_0.ets @@ -0,0 +1,59 @@ +/* + * 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 order +---*/ + +class Order { + order = 0; +} + +function op1(order: Order): void { + order.order++ +} + +function op2(order: Order): void { + order.order++ +} + +type LF = (flag: boolean, order: Order) => boolean + + +function main(): int { + let o0 = new Order + let o1 = new Order + let o2 = new Order + + const op0: LF = (flag: boolean, order: Order) => { order.order++; return flag; } + + op0(false, o0) ? op1(o1) : op2(o2) + + arktest.assertEQ(1, o0.order) + arktest.assertEQ(0, o1.order) + arktest.assertEQ(1, o2.order) + + o0 = new Order + o1 = new Order + o2 = new Order + + op0(true, o0) ? op1(o1) : op2(o2) + + arktest.assertEQ(1, o0.order) + arktest.assertEQ(1, o1.order) + arktest.assertEQ(0, o2.order) + + return 0; +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/09.constructor_declaration/constructor_declaration_no_parenthesis.sts b/static_core/plugins/ets/tests/ets-templates/09.classes/09.constructor_declaration/constructor_declaration_no_parenthesis.sts new file mode 100644 index 0000000000..de33160d0e --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/09.constructor_declaration/constructor_declaration_no_parenthesis.sts @@ -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: Bad class constructor syntax +tags: [compile-only, negative] +---*/ + + +class IAmBad { + constructor {} +} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/09.constructor_declaration/constructor_declaration_with_field.sts b/static_core/plugins/ets/tests/ets-templates/09.classes/09.constructor_declaration/constructor_declaration_with_field.sts new file mode 100644 index 0000000000..8515ebb909 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/09.constructor_declaration/constructor_declaration_with_field.sts @@ -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: Bad class constructor syntax SyntaxError: Declaring fields in parameter list is not supported +tags: [compile-only, negative] +---*/ + + +class IAmBad { + constructor (public name: string) {} +} 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 b1ed6fb02e..d4261b4f3c 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 @@ -2749,6 +2749,9 @@ 07.expressions/06.spread_expression/spex_lmbd_39.ets 07.expressions/06.spread_expression/spex_lmbd_48.ets +#29853. See also 28935 +07.expressions/30.conditional_expressions/MenuOrEmpty.ets + #27465 07.expressions/32.lambda_expression/01.lambda_signature/positive_0.ets 07.expressions/32.lambda_expression/01.lambda_signature/positive_1.ets -- Gitee