From 9cbd243be17ef6be3d6aea4bb221fa8864d7c099 Mon Sep 17 00:00:00 2001 From: Simeon Kosnitsky Date: Sun, 7 Sep 2025 14:08:01 +0300 Subject: [PATCH] Update tests on spec chapter 9.6.4 Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICWR28 Testing: All required pre-merge tests passed. Results are available in the ggwatcher Signed-off-by: Simeon Kosnitsky --- .../class_fields_change.ets | 76 + .../class_fields_change.params.yaml | 776 ++++++++++ .../class_fields_cte.ets | 64 + .../class_fields_cte.params.yaml | 322 ++++ .../class_fields_decl.ets | 76 + .../class_fields_decl.params.yaml | 1347 +++++++++++++++++ .../class_static_fields_change.ets | 76 + .../class_static_fields_change.params.yaml | 408 +++++ .../class_static_fields_cte.ets | 64 + .../class_static_fields_cte.params.yaml | 116 ++ .../class_static_fields_decl.ets | 76 + .../class_static_fields_decl.params.yaml | 575 +++++++ .../field_initialization_with_super.ets | 5 +- .../field_initialization_with_this.ets | 7 +- .../interface_fields_cte.ets | 64 + .../interface_fields_cte.params.yaml | 43 + .../interface_fields_decl.ets | 76 + .../interface_fields_decl.params.yaml | 401 +++++ .../non_static_field_initialization.ets | 2 +- ..._static_field_initialization_reference.ets | 8 +- ...ic_field_self_initialization_reference.ets | 8 +- .../right_initialization_order.ets | 2 +- .../static_field_initialization_reference.ets | 4 +- ...ic_field_self_initialization_reference.ets | 4 +- .../wrong_initialization_order.ets | 26 - .../test-lists/ets-cts/ets-cts-ignored.txt | 55 + 26 files changed, 4636 insertions(+), 45 deletions(-) create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_change.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_change.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_cte.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_cte.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_decl.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_decl.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_change.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_change.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_cte.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_cte.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_decl.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_decl.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/interface_fields_cte.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/interface_fields_cte.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/interface_fields_decl.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/interface_fields_decl.params.yaml delete mode 100644 static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/wrong_initialization_order.ets diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_change.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_change.ets new file mode 100644 index 0000000000..bf92cd02f7 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_change.ets @@ -0,0 +1,76 @@ +/* + * 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 %} + +{% for scl in c.sub_cases_logic %} + +{% for decl in c.decl_variants %} + +/*--- +desc: {{c.desc}} +---*/ + +{%- set ns = namespace() %} + +{%- if 'check_variants' in c %} + {% set check_variants=c.check_variants %} +{%- else %} + {%- set check_variants=[{}] %} +{%- endif %} +{%- for cv in check_variants %} +{%- set cv_id = loop.index %} + +{%- set ns.logic_data = scl %} +{%- for k, v in cv.items() %} + {%- set ns.logic_data = ns.logic_data|replace("[" ~ k ~ "]", v) %} +{%- endfor %} + +{%- set ns.decl = decl %} +{%- for k, v in cv.items() %} + {%- set ns.decl = ns.decl|replace("[" ~ k ~ "]", v) %} +{%- endfor %} + +{%- if cv_id == 1 %} +{%- set ns.first_decl = ns.decl %} +{%- set ns.first_logic_data = ns.logic_data %} +{%- endif %} + +namespace testNS{{cv_id}} { + {{ns.decl|indent(width=2)}} + + export function runTest(): boolean { + {{ns.logic_data|indent(width=4)}} + return true + } +} + +{%- endfor %} + +{{ns.first_decl}} + +function main(): void { +{%- for cv in check_variants %} +{%- set cv_id = loop.index %} +{%- if cv_id == 1 %} + {{ns.first_logic_data|indent(width=2)}} +{% endif %} + arktest.assertTrue(testNS{{cv_id}}.runTest()) +{%- endfor %} +} + +{% endfor %} +{% endfor %} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_change.params.yaml b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_change.params.yaml new file mode 100644 index 0000000000..89e04ef566 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_change.params.yaml @@ -0,0 +1,776 @@ +# 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: + - desc: |- + Checking for changing the value from class method call. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + field: [check_type] = [base_value] + foo(): void { + this.field = [new_value] + } + } + - |- + class A { + field: [check_type] = [base_value] + foo: () => void = (): void => { + this.field = [new_value] + } + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + a.foo() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + + - desc: |- + Checking for changing the value from outside of class. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + field: [check_type] = [base_value] + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + a.field = [new_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + - |- + let a: A = new A() + const lambda = () => { + a.field = [new_value] + } + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + lambda() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + + - desc: |- + Checking for changing the value from function call. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + field: [check_type] = [base_value] + } + function foo(a: A): void { + a.field = [new_value] + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + foo(a) + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + + - desc: |- + >- + Checking for changing the value from function call + with object captured by lambda. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + field: [check_type] = [base_value] + } + function foo(fb: () => void): void { + fb() + } + sub_cases_logic: + - |- + let a: A = new A() + const lambda = () => { + a.field = [new_value] + } + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + foo(lambda) + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + + - desc: |- + >- + Checking for changing the value from outside of class + with different covariant subtype values usage. + decl_variants: + - |- + class Animal { + name: string = "" + } + class Dog extends Animal { + constructor () { + super() + this.name = "dog" + } + } + class Cat extends Animal { + constructor () { + super() + this.name = "cat" + } + } + class C { + field: Animal = new Animal() + } + sub_cases_logic: + - |- + let a: C = new C() + let d: C = new C() + let c: C = new C() + d.field = new Dog() + c.field = new Cat() + arktest.assertTrue(a.field instanceof Animal) + arktest.assertEQ(a.field.name, "") + arktest.assertTrue(d.field instanceof Dog) + arktest.assertEQ(d.field.name, "dog") + arktest.assertTrue(c.field instanceof Cat) + arktest.assertEQ(c.field.name, "cat") + + - desc: |- + >- + Checking for changing the value from outside of class + with different covariant function subtype values usage. + decl_variants: + - |- + class A { + v: int + constructor(v: int = 0) { + this.v = v + } + } + class B extends A { + constructor(v: int = 0) { + super(-v) + } + field(): int { + return 13 + } + } + type HandlerBInt = (a: B, b: int) => A + type HandlerAInt = (a: A, b: int) => B + const handlerAInt: HandlerAInt = (a: A, b: int): B => { + if (a instanceof B){ + return new B(a.field() + b) + } else { + return new B(b) + } + } + type HandlerA = (a: A) => A + const handlerA: HandlerA = (a: A): A => { + if (a instanceof B){ + return new A(a.field()) + } else { + return new A + } + } + type HandlerNothing = () => B + const handlerNothing: HandlerNothing = (): B => { + return new B(567) + } + class C { + field: HandlerBInt = handlerNothing + } + sub_cases_logic: + - |- + let a: C = new C() + let b: C = new C() + let c: C = new C() + b.field = handlerA + c.field = handlerAInt + arktest.assertTrue(a.field instanceof HandlerNothing) + arktest.assertEQ(a.field(new B, 7).v, -567) + arktest.assertTrue(b.field instanceof HandlerA) + arktest.assertEQ(b.field(new B, 7).v, 13) + arktest.assertTrue(c.field instanceof HandlerAInt) + arktest.assertEQ(c.field(new B, 7).v, -20) + + - desc: |- + >- + Checking for changing the value from outside of class + with smart type usage. + decl_variants: + - |- + class Animal { + } + class Dog extends Animal { + field: number = 5 + } + function foo(a: Animal) { + if (a instanceof Dog) { + a.field = 3 + } + } + - |- + class Animal { + } + class Dog extends Animal { + field: number = 5 + } + function foo(a: Animal) { + (a as Dog).field = 3 + } + sub_cases_logic: + - |- + let a: Animal = new Dog() + arktest.assertTrue(a instanceof Dog) + arktest.assertTrue(a.field instanceof number) + arktest.assertEQ(a.field, 5) + foo(a) + arktest.assertTrue(a instanceof Dog) + arktest.assertTrue(a.field instanceof number) + arktest.assertEQ(a.field, 3) + + - desc: |- + >- + Checking for changing the value from outside of class + with subtype usage. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class Base { + field: [check_type] = [base_value] + } + class A extends Base { + } + - |- + class Base { + field: [check_type] = [base_value] + } + class B extends Base { + } + class A extends B { + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + a.field = [new_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + - |- + let a: A = new A() + const lambda = () => { + a.field = [new_value] + } + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + lambda() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + + - desc: |- + Checking for changing field by setter. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + private _field: [check_type] = [base_value] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + } + - |- + class A { + protected _field: [check_type] = [base_value] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + } + - |- + class A { + _field: [check_type] = [base_value] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + a.field = [new_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + + - desc: |- + Checking for changing the value with asynchronous API usage. + check_variants: + - {check_type: "long", new_value: "5"} + - {check_type: "int", new_value: "5"} + - {check_type: "byte", new_value: "5"} + - {check_type: "short", new_value: "5"} + - {check_type: "double", new_value: "7.3"} + - {check_type: "number", new_value: "5"} + - {check_type: "float", new_value: "7.3f"} + - {check_type: "bigint", new_value: "5n"} + - {check_type: "string", new_value: "\"abc\""} + - {check_type: "char", new_value: "c'a'"} + - {check_type: "boolean", new_value: "true"} + - {check_type: "Object", new_value: "5"} + - {check_type: "Object | undefined", new_value: "undefined"} + - {check_type: "Object | undefined | null", new_value: "5"} + - {check_type: "Any", new_value: "5"} + decl_variants: + - |- + class A { + field: Promise<[check_type]> + async foo(): Promise<[check_type]> { + let v: [check_type] = [new_value] + return v + } + constructor() { + this.field = this.foo() + } + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof Promise) + let res = await a.field + arktest.assertTrue(res instanceof [check_type]) + arktest.assertEQ(res, [new_value]) + + - desc: |- + Checking for changing the value with asynchronous API usage. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + field: Promise<[check_type]> = new Promise<[check_type]>( + (resolve, reject) => {resolve([base_value])} + ) + async foo(): Promise<[check_type]> { + let v: [check_type] = [new_value] + return v + } + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof Promise) + let res = await a.field + arktest.assertTrue(res instanceof [check_type]) + arktest.assertEQ(res, [base_value]) + a.field = a.foo() + arktest.assertTrue(a.field instanceof Promise) + res = await a.field + arktest.assertTrue(res instanceof [check_type]) + arktest.assertEQ(res, [new_value]) + + - desc: |- + Checking for changing the value with asynchronous API usage. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + field: [check_type] = [base_value] + async foo(): Promise { + this.field = [new_value] + } + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + await a.foo() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + let res = await a.foo().then((): [check_type] => a.field) + arktest.assertTrue(res instanceof [check_type]) + arktest.assertEQ(res, [new_value]) + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + + - desc: |- + Checking for changing the value with asynchronous API usage. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + field: [check_type] = [base_value] + async foo(): Promise { + return new Promise ( + (resolve: () => void) => { + setTimeout(() => { + this.field = [new_value] + resolve() + }, 1) + } + ) + } + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + await a.foo() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + let res = await a.foo().then((): [check_type] => a.field) + arktest.assertTrue(res instanceof [check_type]) + arktest.assertEQ(res, [new_value]) + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + + - desc: |- + Checking for changing the value from outside of generic class. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + field: T + constructor(a: T) { + this.field = a + } + } + sub_cases_logic: + - |- + let a: A<[check_type]> = new A<[check_type]>([base_value]) + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + a.field = [new_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_cte.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_cte.ets new file mode 100644 index 0000000000..93e5e83574 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_cte.ets @@ -0,0 +1,64 @@ +/* + * 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 %} + +{% if 'sub_cases_logic' in c %} + {% set sub_cases_logic=c.sub_cases_logic %} +{% else %} + {% set sub_cases_logic=[""] %} +{% endif %} +{% for scl in sub_cases_logic %} + +{% for decl in c.decl_variants %} + +{% if 'check_variants' in c %} + {% set check_variants=c.check_variants %} +{% else %} + {% set check_variants=[{}] %} +{% endif %} +{% for cv in check_variants %} + +{% set logic_data = " " ~ (scl|indent(width=2)) %} + +{% set ns = namespace() %} + +{% set ns.logic_data = logic_data %} +{% for k, v in cv.items() %} + {% set ns.logic_data = ns.logic_data|replace("[" ~ k ~ "]", v) %} +{% endfor %} +{% set logic_data=ns.logic_data %} + +{% set ns.decl = decl %} +{% for k, v in cv.items() %} + {% set ns.decl = ns.decl|replace("[" ~ k ~ "]", v) %} +{% endfor %} +{% set decl=ns.decl %} + +/*--- +desc: {{c.desc}} +tags: [compile-only, negative] +---*/ + +{{decl}} + +function main(): void { +{{logic_data}} +} + +{% endfor %} +{% endfor %} +{% endfor %} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_cte.params.yaml b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_cte.params.yaml new file mode 100644 index 0000000000..d85bc0bcf7 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_cte.params.yaml @@ -0,0 +1,322 @@ +# 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: + - desc: |- + >- + Checking on field has no initializer and is not + definitely assigned in the constructor. + check_variants: + - {check_type: "bigint"} + - {check_type: "string"} + - {check_type: "Object"} + decl_variants: + - |- + class A { + field: [check_type] + } + + - desc: |- + >- + Checking on field has no initializer and is not + definitely assigned in the constructor. + decl_variants: + - |- + class C {} + class A { + field: C + } + + - desc: |- + >- + Checking for initialization with different + not covariant subtype values usage. + check_variants: + - {check_value_type: "Cat"} + - {check_value_type: "Animal"} + decl_variants: + - |- + class Animal {} + class Dog extends Animal {} + class Cat extends Animal {} + class C { + field: Dog = new [check_value_type] + } + - |- + class Animal {} + class Dog extends Animal {} + class Cat extends Animal {} + class C { + field: Dog + constructor () { + this.field = new [check_value_type] + } + } + + - desc: |- + >- + Checking for changing the value from outside of constructor + with different not covariant subtype values usage. + check_variants: + - {check_value_type: "Cat"} + - {check_value_type: "Animal"} + decl_variants: + - |- + class Animal {} + class Dog extends Animal {} + class Cat extends Animal {} + class C { + field: Dog = new Dog + } + sub_cases_logic: + - |- + let a: C = new C + a.field = new [check_value_type] + + - desc: |- + >- + Checking for initialization with different + not covariant function subtype values usage. + check_variants: + - {check_value: "handlerCInt"} + - {check_value: "handlerBInt"} + - {check_value: "handlerB"} + - {check_value: "handlerBIntInt"} + - {check_value: "handlerNothing"} + decl_variants: + - |- + class A {} + class B extends A {} + class C extends A {} + type HandlerReq = (a: B, b: int) => B + const handlerReq: HandlerReq = (a: B, b: int): B => { + return new B + } + type HandlerCInt = (a: C, b: int) => B + const handlerCInt: HandlerCInt = (a: C, b: int): B => { + return new B + } + type HandlerBInt = (a: B, b: int) => A + const handlerBInt: HandlerBInt = (a: B, b: int): A => { + return new B + } + type HandlerB = (a: B) => A + const handlerB: HandlerB = (a: B): A => { + return new B + } + type HandlerBIntInt = (a: B, b: int, c: int) => B + const handlerBIntInt: HandlerBIntInt = (a: B, b: int, c: int): B => { + return new B + } + type HandlerNothing = () => C + const handlerNothing: HandlerNothing = (): C => { + return new C + } + class D { + field: HandlerReq = [check_value] + } + - |- + class A {} + class B extends A {} + class C extends A {} + type HandlerReq = (a: B, b: int) => B + const handlerReq: HandlerReq = (a: B, b: int): B => { + return new B + } + type HandlerCInt = (a: C, b: int) => B + const handlerCInt: HandlerCInt = (a: C, b: int): B => { + return new B + } + type HandlerBInt = (a: B, b: int) => A + const handlerBInt: HandlerBInt = (a: B, b: int): A => { + return new B + } + type HandlerB = (a: B) => A + const handlerB: HandlerB = (a: B): A => { + return new B + } + type HandlerBIntInt = (a: B, b: int, c: int) => B + const handlerBIntInt: HandlerBIntInt = (a: B, b: int, c: int): B => { + return new B + } + type HandlerNothing = () => C + const handlerNothing: HandlerNothing = (): C => { + return new C + } + class D { + field: HandlerReq + constructor () { + this.field = [check_value] + } + } + + - desc: |- + >- + Checking for changing the value from outside of constructor + with different not covariant function subtype values usage + check_variants: + - {check_value: "handlerCInt"} + - {check_value: "handlerBInt"} + - {check_value: "handlerB"} + - {check_value: "handlerBIntInt"} + - {check_value: "handlerNothing"} + decl_variants: + - |- + class A {} + class B extends A {} + class C extends A {} + type HandlerReq = (a: B, b: int) => B + const handlerReq: HandlerReq = (a: B, b: int): B => { + return new B + } + type HandlerCInt = (a: C, b: int) => B + const handlerCInt: HandlerCInt = (a: C, b: int): B => { + return new B + } + type HandlerBInt = (a: B, b: int) => A + const handlerBInt: HandlerBInt = (a: B, b: int): A => { + return new B + } + type HandlerB = (a: B) => A + const handlerB: HandlerB = (a: B): A => { + return new B + } + type HandlerBIntInt = (a: B, b: int, c: int) => B + const handlerBIntInt: HandlerBIntInt = (a: B, b: int, c: int): B => { + return new B + } + type HandlerNothing = () => C + const handlerNothing: HandlerNothing = (): C => { + return new C + } + class D { + field: HandlerReq = handlerReq + } + sub_cases_logic: + - |- + let a: D = new D + a.field = [check_value] + + - desc: |- + >- + Checking for initialization with field initializer + by assign this directly. + decl_variants: + - |- + class A { + field = this + } + + - desc: |- + >- + Checking for initialization with field initializer + with call methods of this or supper. + check_variants: + - {check_type: "int", check_value: "5"} + - {check_type: "double", check_value: "7.3"} + - {check_type: "Object", check_value: "5"} + decl_variants: + - |- + class A { + foo (): [check_type] { + return [check_value] + } + field: [check_type] = this.foo() + } + - |- + class Base { + foo (): [check_type] { + return [check_value] + } + } + class A extends Base { + field: [check_type] = super.foo() + } + + - desc: |- + >- + Checking for initialization with field initializer + with capture this. + decl_variants: + - |- + class B {} + function foo (f: () => B) { return f() } + class A { + field1 = new B + field2 = foo(() => this.field1) + } + - |- + class B {} + function foo (f: () => B) { return f() } + class A { + field1 = foo(() => this.field2) + field2 = new B + } + + - desc: |- + >- + Checking for initialization with field initializer + with usage this or super. + check_variants: + - {check_type: "int", check_value: "5"} + - {check_type: "double", check_value: "7.3"} + - {check_type: "Object", check_value: "5"} + decl_variants: + - |- + class A { + v: [check_type] = [check_value] + field: [check_type] = this.v + } + - |- + class A { + private _v: [check_type] = [check_value] + get v(): [check_type] { + return this._v + } + field: [check_type] = this.v + } + - |- + class Base { + private _v: [check_type] = [check_value] + get v(): [check_type] { + return this._v + } + } + class A extends Base { + field: [check_type] = super.v + } + - |- + class A { + private v: [check_type] = [check_value] + private _field: [check_type] = this.v + } + - |- + class Base { + protected _v: [check_type] = [check_value] + } + class A extends Base { + protected _field: [check_type] = super.v + } + + - desc: |- + Readonly fields initialization never uses default values. + check_variants: + - {check_type: "int"} + - {check_type: "double"} + - {check_type: "Object | undefined"} + - {check_type: "Any"} + decl_variants: + - |- + class A { + readonly field: [check_type] + } diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_decl.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_decl.ets new file mode 100644 index 0000000000..bf92cd02f7 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_decl.ets @@ -0,0 +1,76 @@ +/* + * 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 %} + +{% for scl in c.sub_cases_logic %} + +{% for decl in c.decl_variants %} + +/*--- +desc: {{c.desc}} +---*/ + +{%- set ns = namespace() %} + +{%- if 'check_variants' in c %} + {% set check_variants=c.check_variants %} +{%- else %} + {%- set check_variants=[{}] %} +{%- endif %} +{%- for cv in check_variants %} +{%- set cv_id = loop.index %} + +{%- set ns.logic_data = scl %} +{%- for k, v in cv.items() %} + {%- set ns.logic_data = ns.logic_data|replace("[" ~ k ~ "]", v) %} +{%- endfor %} + +{%- set ns.decl = decl %} +{%- for k, v in cv.items() %} + {%- set ns.decl = ns.decl|replace("[" ~ k ~ "]", v) %} +{%- endfor %} + +{%- if cv_id == 1 %} +{%- set ns.first_decl = ns.decl %} +{%- set ns.first_logic_data = ns.logic_data %} +{%- endif %} + +namespace testNS{{cv_id}} { + {{ns.decl|indent(width=2)}} + + export function runTest(): boolean { + {{ns.logic_data|indent(width=4)}} + return true + } +} + +{%- endfor %} + +{{ns.first_decl}} + +function main(): void { +{%- for cv in check_variants %} +{%- set cv_id = loop.index %} +{%- if cv_id == 1 %} + {{ns.first_logic_data|indent(width=2)}} +{% endif %} + arktest.assertTrue(testNS{{cv_id}}.runTest()) +{%- endfor %} +} + +{% endfor %} +{% endfor %} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_decl.params.yaml b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_decl.params.yaml new file mode 100644 index 0000000000..cff6ad0706 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_fields_decl.params.yaml @@ -0,0 +1,1347 @@ +# 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: + - desc: |- + Checking for initialization with default values. + check_variants: + - {check_type: "long", + base_value: "0", new_value: "5"} + - {check_type: "int", + base_value: "0", new_value: "5"} + - {check_type: "byte", + base_value: "0", new_value: "5"} + - {check_type: "short", + base_value: "0", new_value: "5"} + - {check_type: "double", + base_value: "0", new_value: "7.3"} + - {check_type: "number", + base_value: "0", new_value: "5"} + - {check_type: "float", + base_value: "0.0f", new_value: "7.3f"} + - {check_type: "char", + base_value: "c'\\u0000'", new_value: "c'a'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "undefined", new_value: "5"} + - {check_type: "Any", + base_value: "undefined", new_value: "5"} + decl_variants: + - |- + class A { + field: [check_type] + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + a.field = [new_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + + - desc: |- + Checking for initialization with field initializer. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + field: [check_type] = [base_value] + } + - |- + function foo(): [check_type] { + return [base_value] + } + class A { + field: [check_type] = foo() + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + a.field = [new_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + + - desc: |- + Checking for initialization with field initializer. + check_variants: + - {check_type: "C", data_type: "int", + base_obj_lit: "{data: 4}", base_value: "4", + new_obj_lit: "{data: 5}", new_value: "5", + cv_decl_data: "class C {data: int = 0}"} + decl_variants: + - |- + [cv_decl_data] + class A { + field: [check_type] = [base_obj_lit] + } + - |- + [cv_decl_data] + function foo(): [check_type] { + return [base_obj_lit] + } + class A { + field: [check_type] = foo() + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [base_value]) + a.field = [new_obj_lit] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [new_value]) + + - desc: |- + Checking for initialization from constructor. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + field: [check_type] + constructor () { + this.field = [base_value] + } + } + - |- + class A { + field: [check_type] + constructor (arg: [check_type] = [base_value]) { + this.field = arg + } + } + - |- + class A { + field: [check_type] + constructor (...args: Any[]) { + this.field = [base_value] + } + } + - |- + class Base { + protected v: [check_type] = [base_value] + } + class A extends Base { + field: [check_type] + constructor () { + super() + this.field = this.v + } + } + - |- + class A { + protected _field: [check_type] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + constructor () { + this._field = [base_value] + } + } + - |- + class Base { + private _v: [check_type] = [base_value] + get v(): [check_type] { + return this._v + } + } + class A extends Base { + field: [check_type] + constructor () { + super() + this.field = super.v + } + } + - |- + class A { + private _field: [check_type] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + constructor () { + this._field = [base_value] + } + } + - |- + class A { + private _field: [check_type] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + constructor (arg: [check_type] = [base_value]) { + this._field = arg + } + } + - |- + class A { + private _field: [check_type] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + constructor (...args: Any[]) { + this._field = [base_value] + } + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + a.field = [new_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + + - desc: |- + Checking for initialization from constructor. + check_variants: + - {check_type: "C", data_type: "int", + base_obj_lit: "{data: 4}", base_value: "4", + new_obj_lit: "{data: 5}", new_value: "5", + cv_decl_data: "class C {data: int = 0}"} + decl_variants: + - |- + [cv_decl_data] + class A { + field: [check_type] + constructor () { + this.field = [base_obj_lit] + } + } + - |- + [cv_decl_data] + class A { + field: [check_type] + constructor (arg: [check_type] = [base_obj_lit]) { + this.field = arg + } + } + - |- + [cv_decl_data] + class A { + field: [check_type] + constructor (...args: Any[]) { + this.field = [base_obj_lit] + } + } + - |- + [cv_decl_data] + class Base { + protected v: [check_type] = [base_obj_lit] + } + class A extends Base { + field: [check_type] + constructor () { + super() + this.field = this.v + } + } + - |- + [cv_decl_data] + class A { + protected _field: [check_type] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + constructor () { + this._field = [base_obj_lit] + } + } + - |- + [cv_decl_data] + class Base { + private _v: [check_type] = [base_obj_lit] + get v(): [check_type] { + return this._v + } + } + class A extends Base { + field: [check_type] + constructor () { + super() + this.field = super.v + } + } + - |- + [cv_decl_data] + class A { + private _field: [check_type] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + constructor () { + this._field = [base_obj_lit] + } + } + - |- + [cv_decl_data] + class A { + private _field: [check_type] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + constructor (arg: [check_type] = [base_obj_lit]) { + this._field = arg + } + } + - |- + [cv_decl_data] + class A { + private _field: [check_type] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + constructor (...args: Any[]) { + this._field = [base_obj_lit] + } + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [base_value]) + a.field = [new_obj_lit] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [new_value]) + + - desc: |- + Checking for initialization from constructor. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class Base { + protected _field: [check_type] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + } + class A extends Base { + constructor () { + super() + this._field = [base_value] + } + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + a.field = [new_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + + - desc: |- + >- + Checking for initialization from constructor + with subtype usage. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class Base { + protected _field: [check_type] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + constructor () { + this._field = [base_value] + } + } + class A extends Base { + constructor () { + super() + this._field = [new_value] + } + } + sub_cases_logic: + - |- + let a: A = new A() + let b: Base = new Base() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + arktest.assertTrue(b.field instanceof [check_type]) + arktest.assertEQ(b.field, [base_value]) + a.field = [base_value] + b.field = [new_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + arktest.assertTrue(b.field instanceof [check_type]) + arktest.assertEQ(b.field, [new_value]) + + - desc: |- + >- + Checking for initialization from constructor + with subtype usage. + check_variants: + - {check_type: "C", data_type: "int", + base_obj_lit: "{data: 4}", base_value: "4", + new_obj_lit: "{data: 5}", new_value: "5", + cv_decl_data: "class C {data: int = 0}"} + decl_variants: + - |- + [cv_decl_data] + class Base { + protected _field: [check_type] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + constructor () { + this._field = [base_obj_lit] + } + } + class A extends Base { + constructor () { + super() + this._field = [new_obj_lit] + } + } + sub_cases_logic: + - |- + let a: A = new A() + let b: Base = new Base() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [new_value]) + arktest.assertTrue(b.field instanceof [check_type]) + arktest.assertTrue(b.field.data instanceof [data_type]) + arktest.assertEQ(b.field.data, [base_value]) + a.field = [base_obj_lit] + b.field = [new_obj_lit] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [base_value]) + arktest.assertTrue(b.field instanceof [check_type]) + arktest.assertTrue(b.field.data instanceof [data_type]) + arktest.assertEQ(b.field.data, [new_value]) + + - desc: |- + Checking for initialization from constructor. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + field: [check_type] = [base_value] + constructor (v: [check_type] = [base_value]) { + if (v == [new_value]) { + this.field = v + } + } + } + sub_cases_logic: + - |- + let a: A = new A() + let b: A = new A([new_value]) + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + arktest.assertTrue(b.field instanceof [check_type]) + arktest.assertEQ(b.field, [new_value]) + a.field = [new_value] + b.field = [base_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + arktest.assertTrue(b.field instanceof [check_type]) + arktest.assertEQ(b.field, [base_value]) + + - desc: |- + Checking for initialization from constructor. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + field: [check_type] = [base_value] + constructor () { + this.field = [new_value] + } + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + a.field = [base_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + + - desc: |- + Checking for initialization from constructor. + check_variants: + - {check_type: "C", data_type: "int", + base_obj_lit: "{data: 4}", base_value: "4", + new_obj_lit: "{data: 5}", new_value: "5", + cv_decl_data: "class C {data: int = 0}"} + decl_variants: + - |- + [cv_decl_data] + class A { + field: [check_type] = [base_obj_lit] + constructor () { + this.field = [new_obj_lit] + } + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [new_value]) + a.field = [base_obj_lit] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [base_value]) + + - desc: |- + Checking for initialization from object literal. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + field: [check_type] + } + sub_cases_logic: + - |- + let a: A = {field: [base_value]} + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + a.field = [new_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + + - desc: |- + Checking for initialization from object literal. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + field: [check_type] = [base_value] + } + sub_cases_logic: + - |- + let a: A = {field: [new_value]} + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + a.field = [base_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + + - desc: |- + Checking for initialization from object literal. + check_variants: + - {check_type: "C", data_type: "int", + base_obj_lit: "{data: 4}", base_value: "4", + new_obj_lit: "{data: 5}", new_value: "5", + cv_decl_data: "class C {data: int = 0}"} + decl_variants: + - |- + [cv_decl_data] + class A { + field: [check_type] = [base_obj_lit] + } + sub_cases_logic: + - |- + let a: A = {field: [new_obj_lit]} + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [new_value]) + a.field = [base_obj_lit] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [base_value]) + + - desc: |- + Checking for initialization from object literal. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + field: [check_type] = [base_value] + constructor () { + this.field = [base_value] + } + } + sub_cases_logic: + - |- + let a: A = {field: [new_value]} + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + a.field = [base_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + + - desc: |- + Checking for initialization from object literal. + check_variants: + - {check_type: "C", data_type: "int", + base_obj_lit: "{data: 4}", base_value: "4", + new_obj_lit: "{data: 5}", new_value: "5", + cv_decl_data: "class C {data: int = 0}"} + decl_variants: + - |- + [cv_decl_data] + class A { + field: [check_type] = [base_obj_lit] + constructor () { + this.field = [base_obj_lit] + } + } + sub_cases_logic: + - |- + let a: A = {field: [new_obj_lit]} + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [new_value]) + a.field = [base_obj_lit] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [base_value]) + + - desc: |- + >- + Checking for initialization with different + covariant subtype values usage. + check_variants: + - {check_type: "Animal", check_value: "\"\""} + - {check_type: "Dog", check_value: "\"dog\""} + - {check_type: "Cat", check_value: "\"cat\""} + decl_variants: + - |- + class Animal { + name: string = "" + } + class Dog extends Animal { + constructor () { + super() + this.name = "dog" + } + } + class Cat extends Animal { + constructor () { + super() + this.name = "cat" + } + } + class C { + field: Animal = new [check_type] + } + - |- + class Animal { + name: string = "" + } + class Dog extends Animal { + constructor () { + super() + this.name = "dog" + } + } + class Cat extends Animal { + constructor () { + super() + this.name = "cat" + } + } + class C { + field: Animal + constructor() { + this.field = new [check_type] + } + } + sub_cases_logic: + - |- + let a: C = new C() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field.name, [check_value]) + + - desc: |- + >- + Checking for initialization with different + covariant function subtype values usage. + check_variants: + - {check_type: "HandlerNothing", init_value: "handlerNothing", + check_value: "-567"} + - {check_type: "HandlerA", init_value: "handlerA", + check_value: "13"} + - {check_type: "HandlerAInt", init_value: "handlerAInt", + check_value: "-20"} + decl_variants: + - |- + class A { + v: int + constructor(v: int = 0) { + this.v = v + } + } + class B extends A { + constructor(v: int = 0) { + super(-v) + } + field(): int { + return 13 + } + } + type HandlerBInt = (a: B, b: int) => A + type HandlerAInt = (a: A, b: int) => B + const handlerAInt: HandlerAInt = (a: A, b: int): B => { + if (a instanceof B){ + return new B(a.field() + b) + } else { + return new B(b) + } + } + type HandlerA = (a: A) => A + const handlerA: HandlerA = (a: A): A => { + if (a instanceof B){ + return new A(a.field()) + } else { + return new A + } + } + type HandlerNothing = () => B + const handlerNothing: HandlerNothing = (): B => { + return new B(567) + } + class C { + field: HandlerBInt = [init_value] + } + - |- + class A { + v: int + constructor(v: int = 0) { + this.v = v + } + } + class B extends A { + constructor(v: int = 0) { + super(-v) + } + field(): int { + return 13 + } + } + type HandlerBInt = (a: B, b: int) => A + type HandlerAInt = (a: A, b: int) => B + const handlerAInt: HandlerAInt = (a: A, b: int): B => { + if (a instanceof B){ + return new B(a.field() + b) + } else { + return new B(b) + } + } + type HandlerA = (a: A) => A + const handlerA: HandlerA = (a: A): A => { + if (a instanceof B){ + return new A(a.field()) + } else { + return new A + } + } + type HandlerNothing = () => B + const handlerNothing: HandlerNothing = (): B => { + return new B(567) + } + class C { + field: HandlerBInt + constructor() { + this.field = [init_value] + } + } + sub_cases_logic: + - |- + let a: C = new C() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field(new B, 7).v, [check_value]) + + - desc: |- + Checking for initialization field in generic class. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + field: T + constructor(a: T) { + this.field = a + } + } + sub_cases_logic: + - |- + let a: A<[check_type]> = new A<[check_type]>([base_value]) + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + a.field = [new_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + + - desc: |- + >- + The assignment is performed each time an + instance of the class is created. + check_variants: + - {check_type: "long", value_type: "long", + init_value: "5", add_value: "1"} + - {check_type: "int", value_type: "int", + init_value: "5", add_value: "1"} + - {check_type: "byte", value_type: "byte", + init_value: "5", add_value: "1"} + - {check_type: "short", value_type: "short", + init_value: "5", add_value: "1"} + - {check_type: "double", value_type: "double", + init_value: "5", add_value: "1"} + - {check_type: "number", value_type: "number", + init_value: "5", add_value: "1"} + - {check_type: "float", value_type: "float", + init_value: "5.0f", add_value: "1.0f"} + - {check_type: "bigint", value_type: "bigint", + init_value: "5n", add_value: "1n"} + - {check_type: "string", value_type: "string", + init_value: "\"v\"", add_value: "\"n\""} + - {check_type: "Object", value_type: "int", + init_value: "5", add_value: "1"} + - {check_type: "Object | null", value_type: "int", + init_value: "5", add_value: "1"} + - {check_type: "Object | undefined", value_type: "int", + init_value: "5", add_value: "1"} + - {check_type: "Object | undefined | null", value_type: "int", + init_value: "5", add_value: "1"} + - {check_type: "Any", value_type: "int", + init_value: "5", add_value: "1"} + decl_variants: + - |- + let v: [value_type] = [init_value] + function foo(): [value_type] { + let res = v + v += [add_value] + return res + } + class A { + field: [check_type] = foo() + } + - |- + let v: [value_type] = [init_value] + function foo(): [value_type] { + let res = v + v += [add_value] + return res + } + class A { + field: [check_type] + constructor () { + this.field = foo() + } + } + - |- + let v: [value_type] = [init_value] + function foo(): [value_type] { + let res = v + v += [add_value] + return res + } + class A { + field: [check_type] = [init_value] + constructor () { + this.field = foo() + } + } + sub_cases_logic: + - |- + let val: [value_type] = [init_value] + for (let i = 0; i < 5; i++) { + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field instanceof [value_type]) + arktest.assertEQ(a.field, val) + val += [add_value] + } + v = [init_value] + + - desc: |- + Checking for initialization from constructor with namespace usage. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + namespace ns { + export class A { + field: [check_type] + constructor () { + this.field = [base_value] + } + } + } + - |- + namespace ns { + export class A { + field: [check_type] + constructor (arg: [check_type] = [base_value]) { + this.field = arg + } + } + } + - |- + namespace ns { + export class A { + field: [check_type] + constructor (...args: Any[]) { + this.field = [base_value] + } + } + } + - |- + namespace ns { + export class Base { + protected v: [check_type] = [base_value] + } + export class A extends Base { + field: [check_type] + constructor () { + super() + this.field = this.v + } + } + } + - |- + namespace ns { + export class A { + protected _field: [check_type] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + constructor () { + this._field = [base_value] + } + } + } + - |- + namespace ns { + export class Base { + private _v: [check_type] = [base_value] + get v(): [check_type] { + return this._v + } + } + export class A extends Base { + field: [check_type] + constructor () { + super() + this.field = super.v + } + } + } + - |- + namespace ns { + export class A { + private _field: [check_type] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + constructor () { + this._field = [base_value] + } + } + } + - |- + namespace ns { + export class A { + private _field: [check_type] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + constructor (arg: [check_type] = [base_value]) { + this._field = arg + } + } + } + - |- + namespace ns { + export class A { + private _field: [check_type] + get field(): [check_type] { + return this._field + } + set field(a: [check_type]) { + this._field = a + } + constructor (...args: Any[]) { + this._field = [base_value] + } + } + } + sub_cases_logic: + - |- + let a: ns.A = new ns.A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + a.field = [new_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_change.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_change.ets new file mode 100644 index 0000000000..bf92cd02f7 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_change.ets @@ -0,0 +1,76 @@ +/* + * 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 %} + +{% for scl in c.sub_cases_logic %} + +{% for decl in c.decl_variants %} + +/*--- +desc: {{c.desc}} +---*/ + +{%- set ns = namespace() %} + +{%- if 'check_variants' in c %} + {% set check_variants=c.check_variants %} +{%- else %} + {%- set check_variants=[{}] %} +{%- endif %} +{%- for cv in check_variants %} +{%- set cv_id = loop.index %} + +{%- set ns.logic_data = scl %} +{%- for k, v in cv.items() %} + {%- set ns.logic_data = ns.logic_data|replace("[" ~ k ~ "]", v) %} +{%- endfor %} + +{%- set ns.decl = decl %} +{%- for k, v in cv.items() %} + {%- set ns.decl = ns.decl|replace("[" ~ k ~ "]", v) %} +{%- endfor %} + +{%- if cv_id == 1 %} +{%- set ns.first_decl = ns.decl %} +{%- set ns.first_logic_data = ns.logic_data %} +{%- endif %} + +namespace testNS{{cv_id}} { + {{ns.decl|indent(width=2)}} + + export function runTest(): boolean { + {{ns.logic_data|indent(width=4)}} + return true + } +} + +{%- endfor %} + +{{ns.first_decl}} + +function main(): void { +{%- for cv in check_variants %} +{%- set cv_id = loop.index %} +{%- if cv_id == 1 %} + {{ns.first_logic_data|indent(width=2)}} +{% endif %} + arktest.assertTrue(testNS{{cv_id}}.runTest()) +{%- endfor %} +} + +{% endfor %} +{% endfor %} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_change.params.yaml b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_change.params.yaml new file mode 100644 index 0000000000..6c43d688d4 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_change.params.yaml @@ -0,0 +1,408 @@ +# 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: + - desc: |- + Checking for changing the value from outside of class. + check_variants: + - {check_type: "long", + base_value: "0", new_value: "5"} + - {check_type: "int", + base_value: "0", new_value: "5"} + - {check_type: "byte", + base_value: "0", new_value: "5"} + - {check_type: "short", + base_value: "0", new_value: "5"} + - {check_type: "double", + base_value: "0", new_value: "7.3"} + - {check_type: "number", + base_value: "0", new_value: "5"} + - {check_type: "float", + base_value: "0.0f", new_value: "7.3f"} + - {check_type: "char", + base_value: "c'\\u0000'", new_value: "c'a'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "undefined", new_value: "5"} + - {check_type: "Any", + base_value: "undefined", new_value: "5"} + decl_variants: + - |- + class A { + static field: [check_type] + } + sub_cases_logic: + - |- + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + A.field = [new_value] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [new_value]) + A.field = [base_value] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + + - desc: |- + Checking for changing the value from outside of class. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + static field: [check_type] = [base_value] + } + sub_cases_logic: + - |- + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + A.field = [new_value] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [new_value]) + A.field = [base_value] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + + - desc: |- + >- + Checking for changing the value from outside of class + with subtype usage. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class Base { + static field: [check_type] = [base_value] + } + class A extends Base { + } + - |- + class Base { + static field: [check_type] = [base_value] + } + class B extends Base { + } + class A extends B { + } + sub_cases_logic: + - |- + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + A.field = [new_value] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [new_value]) + A.field = [base_value] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + + - desc: |- + Checking for changing the value from class method call. + check_variants: + - {check_type: "long", + base_value: "0", new_value: "5"} + - {check_type: "int", + base_value: "0", new_value: "5"} + - {check_type: "byte", + base_value: "0", new_value: "5"} + - {check_type: "short", + base_value: "0", new_value: "5"} + - {check_type: "double", + base_value: "0", new_value: "7.3"} + - {check_type: "number", + base_value: "0", new_value: "5"} + - {check_type: "float", + base_value: "0.0f", new_value: "7.3f"} + - {check_type: "char", + base_value: "c'\\u0000'", new_value: "c'a'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "undefined", new_value: "5"} + - {check_type: "Any", + base_value: "undefined", new_value: "5"} + decl_variants: + - |- + class A { + static field: [check_type] + foo(a: [check_type]): void { + A.field = a + } + } + - |- + class A { + static field: [check_type] + foo: (a: [check_type]) => void = (a: [check_type]): void => { + A.field = a + } + } + sub_cases_logic: + - |- + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + let a: A = new A() + a.foo([new_value]) + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [new_value]) + a.foo([base_value]) + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + + - desc: |- + Checking for changing the value from class method call. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + static field: [check_type] = [base_value] + foo(a: [check_type]): void { + A.field = a + } + } + - |- + class A { + static field: [check_type] = [base_value] + foo: (a: [check_type]) => void = (a: [check_type]): void => { + A.field = a + } + } + sub_cases_logic: + - |- + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + let a: A = new A() + a.foo([new_value]) + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [new_value]) + a.foo([base_value]) + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + + - desc: |- + Checking for changing the value from constructor. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + static field: [check_type] = [base_value] + constructor () { + A.field = [new_value] + } + } + sub_cases_logic: + - |- + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + let a: A = new A() + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [new_value]) + A.field = [base_value] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + + - desc: |- + >- + Checking for changing the static field 'v' value on each + instance of the class is created. + check_variants: + - {check_type: "long", value_type: "long", + init_value: "5", add_value: "1"} + - {check_type: "int", value_type: "int", + init_value: "5", add_value: "1"} + - {check_type: "byte", value_type: "byte", + init_value: "5", add_value: "1"} + - {check_type: "short", value_type: "short", + init_value: "5", add_value: "1"} + - {check_type: "double", value_type: "double", + init_value: "5", add_value: "1"} + - {check_type: "number", value_type: "number", + init_value: "5", add_value: "1"} + - {check_type: "float", value_type: "float", + init_value: "5.0f", add_value: "1.0f"} + - {check_type: "bigint", value_type: "bigint", + init_value: "5n", add_value: "1n"} + - {check_type: "string", value_type: "string", + init_value: "\"v\"", add_value: "\"n\""} + - {check_type: "Object", value_type: "int", + init_value: "5", add_value: "1"} + - {check_type: "Object | null", value_type: "int", + init_value: "5", add_value: "1"} + - {check_type: "Object | undefined", value_type: "int", + init_value: "5", add_value: "1"} + - {check_type: "Object | undefined | null", value_type: "int", + init_value: "5", add_value: "1"} + - {check_type: "Any", value_type: "int", + init_value: "5", add_value: "1"} + decl_variants: + - |- + function foo(): [value_type] { + let res = A.v + A.v += [add_value] + return res + } + class A { + static v: [value_type] = [init_value] + field: [check_type] = foo() + } + - |- + class A { + static v: [value_type] = [init_value] + field: [check_type] + constructor () { + this.field = A.v + A.v += [add_value] + } + } + - |- + class A { + static v: [value_type] = [init_value] + field: [check_type] = [init_value] + constructor () { + this.field = A.v + A.v += [add_value] + } + } + sub_cases_logic: + - |- + let val: [value_type] = [init_value] + for (let i = 0; i < 5; i++) { + arktest.assertTrue(A.v instanceof [value_type]) + arktest.assertEQ(A.v, val) + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field instanceof [value_type]) + arktest.assertEQ(a.field, val) + val += [add_value] + } + A.v = [init_value] diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_cte.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_cte.ets new file mode 100644 index 0000000000..93e5e83574 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_cte.ets @@ -0,0 +1,64 @@ +/* + * 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 %} + +{% if 'sub_cases_logic' in c %} + {% set sub_cases_logic=c.sub_cases_logic %} +{% else %} + {% set sub_cases_logic=[""] %} +{% endif %} +{% for scl in sub_cases_logic %} + +{% for decl in c.decl_variants %} + +{% if 'check_variants' in c %} + {% set check_variants=c.check_variants %} +{% else %} + {% set check_variants=[{}] %} +{% endif %} +{% for cv in check_variants %} + +{% set logic_data = " " ~ (scl|indent(width=2)) %} + +{% set ns = namespace() %} + +{% set ns.logic_data = logic_data %} +{% for k, v in cv.items() %} + {% set ns.logic_data = ns.logic_data|replace("[" ~ k ~ "]", v) %} +{% endfor %} +{% set logic_data=ns.logic_data %} + +{% set ns.decl = decl %} +{% for k, v in cv.items() %} + {% set ns.decl = ns.decl|replace("[" ~ k ~ "]", v) %} +{% endfor %} +{% set decl=ns.decl %} + +/*--- +desc: {{c.desc}} +tags: [compile-only, negative] +---*/ + +{{decl}} + +function main(): void { +{{logic_data}} +} + +{% endfor %} +{% endfor %} +{% endfor %} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_cte.params.yaml b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_cte.params.yaml new file mode 100644 index 0000000000..4f3ccc03c3 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_cte.params.yaml @@ -0,0 +1,116 @@ +# 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: + - desc: |- + Checking on static field has no initializer. + check_variants: + - {check_type: "bigint"} + - {check_type: "string"} + - {check_type: "Object"} + decl_variants: + - |- + class A { + static field: [check_type] + } + + - desc: |- + Checking on static field has no initializer. + decl_variants: + - |- + class C {} + class A { + static field: C + } + + - desc: |- + >- + Checking for initialization with different + not covariant subtype values usage. + check_variants: + - {check_value_type: "Cat"} + - {check_value_type: "Animal"} + decl_variants: + - |- + class Animal {} + class Dog extends Animal {} + class Cat extends Animal {} + class C { + static field: Dog = new [check_value_type] + } + + - desc: |- + >- + Checking for initialization with different + not covariant function subtype values usage. + check_variants: + - {check_value: "handlerCInt"} + - {check_value: "handlerBInt"} + - {check_value: "handlerB"} + - {check_value: "handlerBIntInt"} + - {check_value: "handlerNothing"} + decl_variants: + - |- + class A {} + class B extends A {} + class C extends A {} + type HandlerReq = (a: B, b: int) => B + const handlerReq: HandlerReq = (a: B, b: int): B => { + return new B + } + type HandlerCInt = (a: C, b: int) => B + const handlerCInt: HandlerCInt = (a: C, b: int): B => { + return new B + } + type HandlerBInt = (a: B, b: int) => A + const handlerBInt: HandlerBInt = (a: B, b: int): A => { + return new B + } + type HandlerB = (a: B) => A + const handlerB: HandlerB = (a: B): A => { + return new B + } + type HandlerBIntInt = (a: B, b: int, c: int) => B + const handlerBIntInt: HandlerBIntInt = (a: B, b: int, c: int): B => { + return new B + } + type HandlerNothing = () => C + const handlerNothing: HandlerNothing = (): C => { + return new C + } + class D { + static field: HandlerReq = [check_value] + } + + - desc: |- + Readonly fields initialization never uses default values. + check_variants: + - {check_type: "int"} + - {check_type: "double"} + - {check_type: "Object | undefined"} + - {check_type: "Any"} + decl_variants: + - |- + class A { + static readonly field: [check_type] + } + + - desc: |- + >- + Error: TS2302: + Static members cannot reference class type parameters + decl_variants: + - |- + class A { + static field: T + } diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_decl.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_decl.ets new file mode 100644 index 0000000000..bf92cd02f7 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_decl.ets @@ -0,0 +1,76 @@ +/* + * 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 %} + +{% for scl in c.sub_cases_logic %} + +{% for decl in c.decl_variants %} + +/*--- +desc: {{c.desc}} +---*/ + +{%- set ns = namespace() %} + +{%- if 'check_variants' in c %} + {% set check_variants=c.check_variants %} +{%- else %} + {%- set check_variants=[{}] %} +{%- endif %} +{%- for cv in check_variants %} +{%- set cv_id = loop.index %} + +{%- set ns.logic_data = scl %} +{%- for k, v in cv.items() %} + {%- set ns.logic_data = ns.logic_data|replace("[" ~ k ~ "]", v) %} +{%- endfor %} + +{%- set ns.decl = decl %} +{%- for k, v in cv.items() %} + {%- set ns.decl = ns.decl|replace("[" ~ k ~ "]", v) %} +{%- endfor %} + +{%- if cv_id == 1 %} +{%- set ns.first_decl = ns.decl %} +{%- set ns.first_logic_data = ns.logic_data %} +{%- endif %} + +namespace testNS{{cv_id}} { + {{ns.decl|indent(width=2)}} + + export function runTest(): boolean { + {{ns.logic_data|indent(width=4)}} + return true + } +} + +{%- endfor %} + +{{ns.first_decl}} + +function main(): void { +{%- for cv in check_variants %} +{%- set cv_id = loop.index %} +{%- if cv_id == 1 %} + {{ns.first_logic_data|indent(width=2)}} +{% endif %} + arktest.assertTrue(testNS{{cv_id}}.runTest()) +{%- endfor %} +} + +{% endfor %} +{% endfor %} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_decl.params.yaml b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_decl.params.yaml new file mode 100644 index 0000000000..8246c2a8f5 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/class_static_fields_decl.params.yaml @@ -0,0 +1,575 @@ +# 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: + - desc: |- + Checking for initialization with default values. + check_variants: + - {check_type: "long", + base_value: "0", new_value: "5"} + - {check_type: "int", + base_value: "0", new_value: "5"} + - {check_type: "byte", + base_value: "0", new_value: "5"} + - {check_type: "short", + base_value: "0", new_value: "5"} + - {check_type: "double", + base_value: "0", new_value: "7.3"} + - {check_type: "number", + base_value: "0", new_value: "5"} + - {check_type: "float", + base_value: "0.0f", new_value: "7.3f"} + - {check_type: "char", + base_value: "c'\\u0000'", new_value: "c'a'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "undefined", new_value: "5"} + - {check_type: "Any", + base_value: "undefined", new_value: "5"} + decl_variants: + - |- + class A { + static field: [check_type] + } + sub_cases_logic: + - |- + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + A.field = [new_value] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [new_value]) + A.field = [base_value] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + + - desc: |- + Checking for initialization with field initializer. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + static field: [check_type] = [base_value] + } + - |- + class A { + static v: [check_type] = [base_value] + static field: [check_type] = A.v + } + - |- + class A { + private static _v: [check_type] = [base_value] + static get v(): [check_type] { + return A._v + } + static field: [check_type] = A.v + } + - |- + class Base { + private static _v: [check_type] = [base_value] + static get v(): [check_type] { + return Base._v + } + } + class A extends Base { + static field: [check_type] = Base.v + } + - |- + function foo(): [check_type] { + return [base_value] + } + class A { + static field: [check_type] = foo() + } + - |- + class A { + private static v: [check_type] = [base_value] + private static _field: [check_type] = A.v + static get field(): [check_type] { + return A._field + } + static set field(a: [check_type]) { + A._field = a + } + } + - |- + class Base { + protected static _v: [check_type] = [base_value] + static get v(): [check_type] { + return Base._v + } + } + class A extends Base { + protected static _field: [check_type] = Base.v + static get field(): [check_type] { + return A._field + } + static set field(a: [check_type]) { + A._field = a + } + } + sub_cases_logic: + - |- + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + A.field = [new_value] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [new_value]) + A.field = [base_value] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + + - desc: |- + Checking for initialization with field initializer. + check_variants: + - {check_type: "C", data_type: "int", + base_obj_lit: "{data: 4}", base_value: "4", + new_obj_lit: "{data: 5}", new_value: "5", + cv_decl_data: "class C {data: int = 0}"} + decl_variants: + - |- + [cv_decl_data] + class A { + static field: [check_type] = [base_obj_lit] + } + - |- + [cv_decl_data] + class A { + static v: [check_type] = [base_obj_lit] + static field: [check_type] = A.v + } + - |- + [cv_decl_data] + class A { + private static _v: [check_type] = [base_obj_lit] + static get v(): [check_type] { + return A._v + } + static field: [check_type] = A.v + } + - |- + [cv_decl_data] + class Base { + private static _v: [check_type] = [base_obj_lit] + static get v(): [check_type] { + return Base._v + } + } + class A extends Base { + static field: [check_type] = Base.v + } + - |- + [cv_decl_data] + function foo(): [check_type] { + return [base_obj_lit] + } + class A { + static field: [check_type] = foo() + } + - |- + [cv_decl_data] + class A { + private static v: [check_type] = [base_obj_lit] + private static _field: [check_type] = A.v + static get field(): [check_type] { + return A._field + } + static set field(a: [check_type]) { + A._field = a + } + } + - |- + [cv_decl_data] + class Base { + protected static _v: [check_type] = [base_obj_lit] + static get v(): [check_type] { + return Base._v + } + } + class A extends Base { + protected static _field: [check_type] = Base.v + static get field(): [check_type] { + return A._field + } + static set field(a: [check_type]) { + A._field = a + } + } + sub_cases_logic: + - |- + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertTrue(A.field.data instanceof [data_type]) + arktest.assertEQ(A.field.data, [base_value]) + A.field = [new_obj_lit] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertTrue(A.field.data instanceof [data_type]) + arktest.assertEQ(A.field.data, [new_value]) + A.field = [base_obj_lit] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertTrue(A.field.data instanceof [data_type]) + arktest.assertEQ(A.field.data, [base_value]) + + - desc: |- + >- + Checking for initialization with different + covariant subtype values usage. + check_variants: + - {check_type: "Animal", check_value: "\"\""} + - {check_type: "Dog", check_value: "\"dog\""} + - {check_type: "Cat", check_value: "\"cat\""} + decl_variants: + - |- + class Animal { + name: string = "" + } + class Dog extends Animal { + constructor () { + super() + this.name = "dog" + } + } + class Cat extends Animal { + constructor () { + super() + this.name = "cat" + } + } + class C { + static field: Animal = new [check_type] + } + sub_cases_logic: + - |- + arktest.assertTrue(C.field instanceof [check_type]) + arktest.assertEQ(C.field.name, [check_value]) + + - desc: |- + >- + Checking for initialization with different + covariant function subtype values usage. + check_variants: + - {check_type: "HandlerNothing", init_value: "handlerNothing", + check_value: "-567"} + - {check_type: "HandlerA", init_value: "handlerA", + check_value: "13"} + - {check_type: "HandlerAInt", init_value: "handlerAInt", + check_value: "-20"} + decl_variants: + - |- + class A { + v: int + constructor(v: int = 0) { + this.v = v + } + } + class B extends A { + constructor(v: int = 0) { + super(-v) + } + foo(): int { + return 13 + } + } + type HandlerBInt = (a: B, b: int) => A + type HandlerAInt = (a: A, b: int) => B + const handlerAInt: HandlerAInt = (a: A, b: int): B => { + if (a instanceof B){ + return new B(a.foo() + b) + } else { + return new B(b) + } + } + type HandlerA = (a: A) => A + const handlerA: HandlerA = (a: A): A => { + if (a instanceof B){ + return new A(a.foo()) + } else { + return new A + } + } + type HandlerNothing = () => B + const handlerNothing: HandlerNothing = (): B => { + return new B(567) + } + class C { + static field: HandlerBInt = [init_value] + } + sub_cases_logic: + - |- + arktest.assertTrue(C.field instanceof [check_type]) + arktest.assertEQ(C.field(new B, 7).v, [check_value]) + + - desc: |- + Checking for changing the value from static block. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + static field: [check_type] + static { + A.field = [base_value] + } + } + sub_cases_logic: + - |- + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + A.field = [new_value] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [new_value]) + A.field = [base_value] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + + - desc: |- + Checking for changing the value from static block. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined", + base_value: "undefined", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + class A { + static field: [check_type] = [base_value] + static { + A.field = [new_value] + } + } + sub_cases_logic: + - |- + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [new_value]) + A.field = [base_value] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [base_value]) + A.field = [new_value] + arktest.assertTrue(A.field instanceof [check_type]) + arktest.assertEQ(A.field, [new_value]) + + - desc: |- + Checking for initialization with namespace usage. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + namespace ns { + export class A { + static field: [check_type] = [base_value] + } + } + - |- + namespace ns { + export class A { + static v: [check_type] = [base_value] + static field: [check_type] = A.v + } + } + - |- + namespace ns { + export class A { + private static _v: [check_type] = [base_value] + static get v(): [check_type] { + return A._v + } + static field: [check_type] = A.v + } + } + - |- + namespace ns { + export class Base { + private static _v: [check_type] = [base_value] + static get v(): [check_type] { + return Base._v + } + } + export class A extends Base { + static field: [check_type] = Base.v + } + } + - |- + namespace ns { + function foo(): [check_type] { + return [base_value] + } + export class A { + static field: [check_type] = foo() + } + } + - |- + namespace ns { + export class A { + private static v: [check_type] = [base_value] + private static _field: [check_type] = A.v + static get field(): [check_type] { + return A._field + } + static set field(a: [check_type]) { + A._field = a + } + } + } + - |- + namespace ns { + export class Base { + protected static _v: [check_type] = [base_value] + static get v(): [check_type] { + return Base._v + } + } + export class A extends Base { + protected static _field: [check_type] = Base.v + static get field(): [check_type] { + return A._field + } + static set field(a: [check_type]) { + A._field = a + } + } + } + - |- + namespace ns { + export class A { + static field: [check_type] + static { + A.field = [base_value] + } + } + } + - |- + namespace ns { + export class A { + static field: [check_type] = [new_value] + static { + A.field = [base_value] + } + } + } + sub_cases_logic: + - |- + arktest.assertTrue(ns.A.field instanceof [check_type]) + arktest.assertEQ(ns.A.field, [base_value]) + ns.A.field = [new_value] + arktest.assertTrue(ns.A.field instanceof [check_type]) + arktest.assertEQ(ns.A.field, [new_value]) + ns.A.field = [base_value] + arktest.assertTrue(ns.A.field instanceof [check_type]) + arktest.assertEQ(ns.A.field, [base_value]) diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/field_initialization_with_super.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/field_initialization_with_super.ets index 4d80802f27..5e4e3f0e12 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/field_initialization_with_super.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/field_initialization_with_super.ets @@ -16,8 +16,9 @@ limitations under the License. /*--- desc: Non-static field initialization with keyword 'super'. assert: >- - It there is an initializer in a non-static field declaration, then the following rules apply to the initializer. - The initializer may refer to the current object using the keyword this or the keyword super. + The instance field initializer expression cannot use + this or super directly in any form. +tags: [compile-only, negative] ---*/ class A { diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/field_initialization_with_this.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/field_initialization_with_this.ets index 6d74067cca..d95e5a9bd0 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/field_initialization_with_this.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/field_initialization_with_this.ets @@ -16,8 +16,9 @@ limitations under the License. /*--- desc: Non-static field initialization with keyword 'this'. assert: >- - It there is an initializer in a non-static field declaration, then the following rules apply to the initializer. - The initializer may refer to the current object using the keyword this or the keyword super. + The instance field initializer expression cannot use + this or super directly in any form. +tags: [compile-only, negative] ---*/ class A { @@ -28,5 +29,5 @@ class A { function main(): void { let instance: A = new A(); - arktest.assertEQ( instance.x, 5 ); + arktest.assertEQ(instance.x, 5); } diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/interface_fields_cte.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/interface_fields_cte.ets new file mode 100644 index 0000000000..93e5e83574 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/interface_fields_cte.ets @@ -0,0 +1,64 @@ +/* + * 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 %} + +{% if 'sub_cases_logic' in c %} + {% set sub_cases_logic=c.sub_cases_logic %} +{% else %} + {% set sub_cases_logic=[""] %} +{% endif %} +{% for scl in sub_cases_logic %} + +{% for decl in c.decl_variants %} + +{% if 'check_variants' in c %} + {% set check_variants=c.check_variants %} +{% else %} + {% set check_variants=[{}] %} +{% endif %} +{% for cv in check_variants %} + +{% set logic_data = " " ~ (scl|indent(width=2)) %} + +{% set ns = namespace() %} + +{% set ns.logic_data = logic_data %} +{% for k, v in cv.items() %} + {% set ns.logic_data = ns.logic_data|replace("[" ~ k ~ "]", v) %} +{% endfor %} +{% set logic_data=ns.logic_data %} + +{% set ns.decl = decl %} +{% for k, v in cv.items() %} + {% set ns.decl = ns.decl|replace("[" ~ k ~ "]", v) %} +{% endfor %} +{% set decl=ns.decl %} + +/*--- +desc: {{c.desc}} +tags: [compile-only, negative] +---*/ + +{{decl}} + +function main(): void { +{{logic_data}} +} + +{% endfor %} +{% endfor %} +{% endfor %} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/interface_fields_cte.params.yaml b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/interface_fields_cte.params.yaml new file mode 100644 index 0000000000..7504d6a80a --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/interface_fields_cte.params.yaml @@ -0,0 +1,43 @@ +# 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: + - desc: |- + >- + Checking creation of interface object + with missing required property. + check_variants: + - {check_type: "int"} + - {check_type: "double"} + - {check_type: "Object | undefined"} + - {check_type: "Any"} + decl_variants: + - |- + interface I { + field: [check_type] + } + sub_cases_logic: + - |- + let a: I = {} + + - desc: |- + static modifier cannot appear on a type member. + check_variants: + - {check_type: "int"} + - {check_type: "double"} + - {check_type: "Any"} + decl_variants: + - |- + interface I { + static field: [check_type] + } diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/interface_fields_decl.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/interface_fields_decl.ets new file mode 100644 index 0000000000..bf92cd02f7 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/interface_fields_decl.ets @@ -0,0 +1,76 @@ +/* + * 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 %} + +{% for scl in c.sub_cases_logic %} + +{% for decl in c.decl_variants %} + +/*--- +desc: {{c.desc}} +---*/ + +{%- set ns = namespace() %} + +{%- if 'check_variants' in c %} + {% set check_variants=c.check_variants %} +{%- else %} + {%- set check_variants=[{}] %} +{%- endif %} +{%- for cv in check_variants %} +{%- set cv_id = loop.index %} + +{%- set ns.logic_data = scl %} +{%- for k, v in cv.items() %} + {%- set ns.logic_data = ns.logic_data|replace("[" ~ k ~ "]", v) %} +{%- endfor %} + +{%- set ns.decl = decl %} +{%- for k, v in cv.items() %} + {%- set ns.decl = ns.decl|replace("[" ~ k ~ "]", v) %} +{%- endfor %} + +{%- if cv_id == 1 %} +{%- set ns.first_decl = ns.decl %} +{%- set ns.first_logic_data = ns.logic_data %} +{%- endif %} + +namespace testNS{{cv_id}} { + {{ns.decl|indent(width=2)}} + + export function runTest(): boolean { + {{ns.logic_data|indent(width=4)}} + return true + } +} + +{%- endfor %} + +{{ns.first_decl}} + +function main(): void { +{%- for cv in check_variants %} +{%- set cv_id = loop.index %} +{%- if cv_id == 1 %} + {{ns.first_logic_data|indent(width=2)}} +{% endif %} + arktest.assertTrue(testNS{{cv_id}}.runTest()) +{%- endfor %} +} + +{% endfor %} +{% endfor %} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/interface_fields_decl.params.yaml b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/interface_fields_decl.params.yaml new file mode 100644 index 0000000000..02089d0177 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/interface_fields_decl.params.yaml @@ -0,0 +1,401 @@ +# 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: + - desc: |- + Checking the implementation of interface field. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + interface I { + field: [check_type] + } + class A implements I { + field: [check_type] = [base_value] + } + - |- + interface I { + field: [check_type] + } + class A implements I { + field: [check_type] + constructor () { + this.field = [base_value] + } + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + a.field = [new_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + - |- + let a: A = {field: [new_value]} + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + a.field = [base_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + + - desc: |- + Checking the implementation of interface field. + check_variants: + - {check_type: "C", data_type: "int", + base_obj_lit: "{data: 4}", base_value: "4", + new_obj_lit: "{data: 5}", new_value: "5", + cv_decl_data: "class C {data: int = 0}"} + decl_variants: + - |- + [cv_decl_data] + interface I { + field: [check_type] + } + class A implements I { + field: [check_type] = [base_obj_lit] + } + - |- + [cv_decl_data] + interface I { + field: [check_type] + } + class A implements I { + field: [check_type] + constructor () { + this.field = [base_obj_lit] + } + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [base_value]) + a.field = [new_obj_lit] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [new_value]) + + - desc: |- + Checking the implementation of interface field. + check_variants: + - {check_type: "C", data_type: "int", + base_obj_lit: "{data: 4}", base_value: "4", + new_obj_lit: "{data: 5}", new_value: "5", + cv_decl_data: "class C {data: int = 0}"} + decl_variants: + - |- + [cv_decl_data] + interface I { + field: [check_type] + } + class A implements I { + field: [check_type] = new [check_type] + } + - |- + [cv_decl_data] + interface I { + field: [check_type] + } + class A implements I { + field: [check_type] + constructor () { + this.field = new [check_type] + } + } + sub_cases_logic: + - |- + let a: A = {field: [base_obj_lit]} + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [base_value]) + a.field = [new_obj_lit] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [new_value]) + + - desc: |- + Checking the implementation of interface readonly field. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + interface I { + readonly field: [check_type] + } + class A implements I { + field: [check_type] = [base_value] + } + - |- + interface I { + readonly field: [check_type] + } + class A implements I { + field: [check_type] + constructor () { + this.field = [base_value] + } + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + a.field = [new_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + - |- + let a: A = {field: [new_value]} + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + a.field = [base_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + + - desc: |- + Checking the implementation of interface readonly field. + check_variants: + - {check_type: "C", data_type: "int", + base_obj_lit: "{data: 4}", base_value: "4", + new_obj_lit: "{data: 5}", new_value: "5", + cv_decl_data: "class C {data: int = 0}"} + decl_variants: + - |- + [cv_decl_data] + interface I { + readonly field: [check_type] + } + class A implements I { + field: [check_type] = [base_obj_lit] + } + - |- + [cv_decl_data] + interface I { + readonly field: [check_type] + } + class A implements I { + field: [check_type] + constructor () { + this.field = [base_obj_lit] + } + } + sub_cases_logic: + - |- + let a: A = new A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [base_value]) + a.field = [new_obj_lit] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [new_value]) + + - desc: |- + Checking the implementation of interface readonly field. + check_variants: + - {check_type: "C", data_type: "int", + base_obj_lit: "{data: 4}", base_value: "4", + new_obj_lit: "{data: 5}", new_value: "5", + cv_decl_data: "class C {data: int = 0}"} + decl_variants: + - |- + [cv_decl_data] + interface I { + readonly field: [check_type] + } + class A implements I { + field: [check_type] = new [check_type] + } + - |- + [cv_decl_data] + interface I { + readonly field: [check_type] + } + class A implements I { + field: [check_type] + constructor () { + this.field = new [check_type] + } + } + sub_cases_logic: + - |- + let a: A = {field: [base_obj_lit]} + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [base_value]) + a.field = [new_obj_lit] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertTrue(a.field.data instanceof [data_type]) + arktest.assertEQ(a.field.data, [new_value]) + + - desc: |- + Checking creation interface object with field. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + interface I { + field: [check_type] + } + sub_cases_logic: + - |- + let a: I = {field: [base_value]} + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + a.field = [new_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + + - desc: |- + Checking the implementation of interface in namespace. + check_variants: + - {check_type: "long", + base_value: "4", new_value: "5"} + - {check_type: "int", + base_value: "4", new_value: "5"} + - {check_type: "byte", + base_value: "4", new_value: "5"} + - {check_type: "short", + base_value: "4", new_value: "5"} + - {check_type: "double", + base_value: "4", new_value: "7.3"} + - {check_type: "number", + base_value: "4", new_value: "5"} + - {check_type: "float", + base_value: "4.5f", new_value: "7.3f"} + - {check_type: "bigint", + base_value: "4n", new_value: "5n"} + - {check_type: "string", + base_value: "\"abc\"", new_value: "\"efg\""} + - {check_type: "char", + base_value: "c'a'", new_value: "c'b'"} + - {check_type: "boolean", + base_value: "false", new_value: "true"} + - {check_type: "Object", + base_value: "4", new_value: "5"} + - {check_type: "Object | undefined | null", + base_value: "4", new_value: "5"} + - {check_type: "Any", + base_value: "4", new_value: "5"} + decl_variants: + - |- + namespace ns { + export interface I { + field: [check_type] + foo: () => void + } + export class A implements I { + field: [check_type] = [base_value] + foo: () => void = (): void => { + this.field = [new_value] + } + } + } + sub_cases_logic: + - |- + let a: ns.A = new ns.A() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) + a.foo() + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + - |- + let a: ns.A = {field: [new_value]} + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [new_value]) + a.field = [base_value] + arktest.assertTrue(a.field instanceof [check_type]) + arktest.assertEQ(a.field, [base_value]) diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/non_static_field_initialization.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/non_static_field_initialization.ets index de34353d0d..b011c22791 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/non_static_field_initialization.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/non_static_field_initialization.ets @@ -27,5 +27,5 @@ class A { function main(): void { let instance: A = new A(); - arktest.assertTrue( instance.x == 5 ); + arktest.assertEQ(instance.x, 5); } diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/non_static_field_initialization_reference.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/non_static_field_initialization_reference.ets index e76f5b073c..21ab6bdd1c 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/non_static_field_initialization_reference.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/non_static_field_initialization_reference.ets @@ -14,14 +14,14 @@ limitations under the License. ---*/ /*--- -desc: Static field 'f' have reference in static variable. +desc: Non-static field 'f' have reference in non-static variable. assert: >- - For a reference to a non-static field f declared in class or interface C, it is a compile-time error if. - The reference appears either in a non-static variable's initializer of C or in a static initializer of C. + The instance field initializer expression cannot use + this or super directly in any form. tags: [compile-only, negative] ---*/ class C { - public a: int = f + 5; public f: int; + public a: int = this.f + 5; } diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/non_static_field_self_initialization_reference.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/non_static_field_self_initialization_reference.ets index a9ec38804f..3a3430d1f7 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/non_static_field_self_initialization_reference.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/non_static_field_self_initialization_reference.ets @@ -14,13 +14,13 @@ limitations under the License. ---*/ /*--- -desc: Non-static field 'f' have reference in static. +desc: Non-static field 'f' have reference to itself. assert: >- - For a reference to a non-static field f declared in class or interface C, it is a compile-time error if. - The reference appears in the initializer of f's own declaration or at a point prior to f's declaration. + The instance field initializer expression cannot use + this or super directly in any form. tags: [compile-only, negative] ---*/ class C { - public f: int = f + 5; + public f: int = this.f + 5; } diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/right_initialization_order.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/right_initialization_order.ets index f67f9843cf..f5042deba0 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/right_initialization_order.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/right_initialization_order.ets @@ -25,5 +25,5 @@ class A { } function main(): void { - arktest.assertTrue( A.x == 5 ); + arktest.assertEQ(A.x, 5); } diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/static_field_initialization_reference.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/static_field_initialization_reference.ets index 8b54e7dd51..35c2fae0f1 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/static_field_initialization_reference.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/static_field_initialization_reference.ets @@ -22,6 +22,6 @@ tags: [compile-only, negative] ---*/ class C { - public static a: int = f + 5; - public static f: int; + public static a: int = C.f + 5; + public static f: int = C.a; } diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/static_field_self_initialization_reference.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/static_field_self_initialization_reference.ets index 9eafb15d35..4f8229042d 100644 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/static_field_self_initialization_reference.ets +++ b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/static_field_self_initialization_reference.ets @@ -14,7 +14,7 @@ limitations under the License. ---*/ /*--- -desc: Non-static field 'f' have reference in static. +desc: Non-static field 'f' have reference to itself. assert: >- For a reference to a static field f declared in class or interface C, it is a compile-time error if. The reference appears in the initializer of f's own declaration or at a point prior to f's declaration. @@ -22,5 +22,5 @@ tags: [compile-only, negative] ---*/ class C { - public static f: int = f + 5; + public static f: int = C.f + 5; } diff --git a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/wrong_initialization_order.ets b/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/wrong_initialization_order.ets deleted file mode 100644 index 7738453f65..0000000000 --- a/static_core/plugins/ets/tests/ets-templates/09.classes/06.field_declarations/04.field_initialization/wrong_initialization_order.ets +++ /dev/null @@ -1,26 +0,0 @@ -/*--- -Copyright (c) 2021-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: Check that readonly static field initialized first. -assert: Note that static fields that are readonly variables are initialized before other static fields. -tags: [negative, compile-only] ----*/ - -class A { - public static readonly y: int = x; - - public static x: int = 5; -} 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 0aa140820d..1c16e0c845 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 @@ -1373,6 +1373,61 @@ 09.classes/06.field_declarations/02.readonly_constant_fields/class_static_readonly_fields_cte_10.ets 09.classes/06.field_declarations/02.readonly_constant_fields/class_static_readonly_fields_cte_11.ets +#29936 +09.classes/06.field_declarations/04.field_initialization/class_fields_change_20.ets + +#29301 +09.classes/06.field_declarations/04.field_initialization/class_fields_change_21.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_change_22.ets + +#29575 +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_25.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_26.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_27.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_28.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_29.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_30.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_31.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_32.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_33.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_34.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_35.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_36.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_37.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_38.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_39.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_40.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_41.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_42.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_43.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_44.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_45.ets +09.classes/06.field_declarations/04.field_initialization/field_initialization_with_super.ets +09.classes/06.field_declarations/04.field_initialization/field_initialization_with_this.ets +09.classes/06.field_declarations/04.field_initialization/non_static_field_initialization_reference.ets +09.classes/06.field_declarations/04.field_initialization/non_static_field_self_initialization_reference.ets + +#29684 +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_49.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_50.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_51.ets +09.classes/06.field_declarations/04.field_initialization/class_fields_cte_52.ets +09.classes/06.field_declarations/04.field_initialization/class_static_fields_cte_11.ets +09.classes/06.field_declarations/04.field_initialization/class_static_fields_cte_12.ets +09.classes/06.field_declarations/04.field_initialization/class_static_fields_cte_13.ets +09.classes/06.field_declarations/04.field_initialization/class_static_fields_cte_14.ets + +#29937 +09.classes/06.field_declarations/04.field_initialization/class_static_fields_cte_15.ets + +#29938 +09.classes/06.field_declarations/04.field_initialization/interface_fields_cte_2.ets +09.classes/06.field_declarations/04.field_initialization/interface_fields_cte_3.ets + +#29713 +09.classes/06.field_declarations/04.field_initialization/static_field_initialization_reference.ets +09.classes/06.field_declarations/04.field_initialization/static_field_self_initialization_reference.ets + #29304 09.classes/06.field_declarations/05.fields_with_late_initialization/fields_with_late_initialization_cte_239.ets 09.classes/06.field_declarations/05.fields_with_late_initialization/fields_with_late_initialization_cte_240.ets -- Gitee